I'm working with Spring STS, and creating a spring template project.
(Also with Eclipse-juno, spring 3.1).
My welcome page of the application is a simple form:
When i deliver the form ,My controller comes into place:Code:<div id="editPresPage"> <form action="editPresPage.do" method="post"> <label>Enter Page Text</label><input type="text" name="page_text"/><br> <input type="submit" value="Add New Page"/> </form> </div>
The controller needs to perform the check method (which is marked) from My Service Layer interface:Code:@Controller @RequestMapping(value = "/") public class HomeController { private Page_manager_service page_manager_service; public void setPage_manager_service(Page_manager_service page_manager_service) { this.page_manager_service = page_manager_service; } @RequestMapping(value="/editPresPage",method = RequestMethod.POST) public ModelAndView EditPresPage() { page_manager_service.check(); return new ModelAndView("thanks"); }
The Service Layer implementation:Code:public interface Page_manager_service { public void check(); }
But i'll getting the following error while executing the check method:Code:public class Page_manager_service_mock_Impl implements Page_manager_service { public void check() { System.out.println("check method was done!!!"); } }
java.lang.NullPointerException
at my.topLevel.pack.HomeController.EditPresPage(HomeC ontroller.java:64)
Here is my servlet-context.xml:
Code:<?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --> <!-- Enables the Spring MVC @Controller programming model --> <annotation-driven /> <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --> <resources mapping="/resources/**" location="/resources/" /> <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --> <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <beans:property name="prefix" value="/WEB-INF/views/" /> <beans:property name="suffix" value=".jsp" /> </beans:bean> <context:component-scan base-package="my.topLevel.pack" /> </beans:beans>
Here is my root-context.xml (you can see that i wired the "page_manager_service" bean):
I did not change anything in the web.xml file.Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!-- Root Context: defines shared resources visible to all other web components --> <context:annotation-config/> <!-- Service Beans --> <bean id="page_manager_service" class="my.topLevel.pack.Services.Page_manager_service_mock_Impl"> </bean> </beans>
This is how my project looks like - you can see that the service layer implementation is being injected because there is an "s" on it:
mypath.jpg
I Don't know why i'm getting this error..


Reply With Quote
