Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8839765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:18:38+00:00 2026-06-14T10:18:38+00:00

I tried to change my Spring MVC Form Controller to Annotation Controller but i’ve

  • 0

I tried to change my Spring MVC Form Controller to Annotation Controller but i’ve got some problems.

When i deploy my app on my glassfish server, i’ve got the following error when i would like acces to hello.htm

Avertissement: StandardWrapperValve[dispatcher]: PWC1406: Servlet.service() for servlet dispatcher threw exception
java.lang.NullPointerException
at hibernateTest.web.InventoryController.getClient(InventoryController.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at     com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)

This is my web.xml :

<?xml version="1.0" encoding="UTF-8"?> 

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns="http://java.sun.com/xml/ns/javaee" 
     xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
     id="WebApp_ID" 
     version="2.5">

<context-param> 
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/dispatcher-servlet.xml, /WEB-INF/applicationContext.xml
    </param-value>
</context-param> 

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>*.htm</url-pattern>
</servlet-mapping>

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

dispatcher-servlet.xml :

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
  default-autowire="byName">

<context:component-scan base-package="hibernateTest.web" />

<context:annotation-config/>

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
      p:prefix="/WEB-INF/jsp/" 
      p:suffix=".jsp" />

<bean id="propertyConfigurer" 
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:jdbc.properties</value>
        </list>
    </property>
</bean> 

InventoryController :

import com.mysql.jdbc.Constants;
import hibernateTest.service.ProductManager;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class InventoryController { 

protected final Log logger = LogFactory.getLog(getClass()); 

private ProductManager productManager; 

public void setProductManager(ProductManager productManager) {
    this.productManager = productManager;
} 

@RequestMapping(value="/hello.htm",method = RequestMethod.GET)
public String getClient(ModelMap model) {

    logger.info("returning hello view"); 
    model.addAttribute("products", this.productManager.getProducts());
    return "hello"; 
}
 }

SimpleProductManager :

import hibernateTest.domain.Product; 
import hibernateTest.repository.ProductDao;
 import java.util.List; 
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

@Service()
public class SimpleProductManager implements ProductManager { 

protected final Log logger = LogFactory.getLog(getClass()); 

private ProductDao productDao; 

public void increasePrice(int percentage) {

    List<Product> products = productDao.getProductList();

    if (products != null) {

        for (Product product : products) {

            double newPrice = product.getPrice().doubleValue() * (100 + percentage)/100;
            product.setPrice(newPrice);
            productDao.saveProduct(product);

        }

    }

} 

public void createProduct(String description, Double price) {

    Product prod = new Product();

    prod.setDescription(description);
    prod.setPrice(price);

    logger.info("Class SimpleProductManager - Description set to " + description);
    logger.info("Class SimpleProductManager - Price set to " + price);

    productDao.insertProduct(prod);

}

public List<Product> getProducts() {

    return productDao.getProductList();

} 

public void setProductDao(ProductDao productDao) {

    this.productDao = productDao;

} 
}

JdbcProductDao :

import hibernateTest.domain.Product;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List; 

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;

@Repository
public class JdbcProductDao extends JdbcDaoSupport implements ProductDao { 

/** Logger for this class and subclasses */
protected final Log logger = LogFactory.getLog(getClass()); 

public List<Product> getProductList() {

    logger.info("Getting products!");

    List<Product> products = getJdbcTemplate().query(
            "select id, description, price from products", 
            new ProductMapper());

    return products;

} 

public void saveProduct(Product prod) {

    logger.info("Saving product: " + prod.getDescription());

    int count = getJdbcTemplate().update(
            "update products set description = ?, price = ? where id = ?",
            new Object[]{prod.getDescription(), prod.getPrice(), prod.getId()});

    logger.info("Rows affected: " + count);

}    

public void insertProduct(Product prod) {

    logger.info("Inserting product: " + prod.getDescription());

    getJdbcTemplate().update(
            "insert into products (description, price) values (?, ?)",
            new Object[]{prod.getDescription(), prod.getPrice()});

    logger.info("Inserting product " + prod.getDescription() + "ok");

}
private static class ProductMapper implements ParameterizedRowMapper<Product> { 

    public Product mapRow(ResultSet rs, int rowNum) throws SQLException {

        Product prod = new Product();

        prod.setId(rs.getInt("id"));
        prod.setDescription(rs.getString("description"));
        prod.setPrice(new Double(rs.getDouble("price")));

        return prod;

    } 

} 

}

Thanks for helping !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:18:39+00:00Added an answer on June 14, 2026 at 10:18 am

    You need to tell the controller what ProductManager is by Autowiring it.

    @autowired
    private ProductManager productManager;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to listen file change event in BlackBerry base on FileExplorer example, but
I have built an ASP.NET MVC app some time ago, and after a few
I have a Spring MVC web application with conroller like below : @Controller public
I'm trying to use spring-test-mvc for testing a controller in my little application. Since
I'm developing using IntelliJ 11u on a spring mvc application using tomcat. I tried
I'm creating some simple webpage with Spring MVC, Hibernate4 and MySQL5. One of models
I want to change a sub string forecolor in my gridview . I tried
I tried to change the data folder path of MySQL by changing the datadir
I've tried to change filenames using following script: find dir/ -type f -exec mv
I'm using Ubuntu 12.04 I tried to change my default apache2 port from 80

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.