这几天在学习SpringMVC,在与Spring集成时,出现了两个小问题,记录下来,提醒自己,同时如果大家遇到同样问题,能够帮助大家的话,那我就感到幸哉了!

1.java.lang.NullPointerException

SEVERE: Servlet.service() for servlet [springMVC] in context with path [/SpringMVC-Spring] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root causejava.lang.NullPointerException    at com.kyt.service.impl.UserServiceImpl.add(UserServiceImpl.java:15)    at com.kyt.web.controller.RegisterController.register(RegisterController.java:20)    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)

解决方法:

在配置文件中加入注解的相关配置,下面的配置中,注释的是Spring2.5采用的,未注释的是Spring3.0采用的。

2.页面404

十二月 01, 2013 10:15:15 下午 org.springframework.web.servlet.DispatcherServlet noHandlerFoundWARNING: No mapping found for HTTP request with URI [/SpringMVC-Spring/user/register] in DispatcherServlet with name 'springMVC'

解决方法:

扫描包配置错误