您的位置:首页 > 编程语言 > Java开发

Spring与SpringMVC集成出现的问题

2013-12-01 22:18 405 查看
这几天在学习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 cause
java.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采用的。
<!-- <context:annotation-config></context:annotation-config> -->
<!-- 注解配置 -->
<context:component-scan base-package="com.kyt"></context:component-scan>
<mvc:annotation-driven />
2.页面404
十二月 01, 2013 10:15:15 下午 org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SpringMVC-Spring/user/register] in DispatcherServlet with name 'springMVC'


解决方法:
扫描包配置错误

<context:component-scan base-package="com.kyt"></context:component-scan>


本文出自 “quietboy's blog” 博客,请务必保留此出处http://quietboy.blog.51cto.com/6711298/1334481
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: