做为spring的新手,很愿意尝试这样的优秀框架,但最近做项目时,总是碰到恼人的问题。
我用的时2.5的注解配置,
springmvc-servlet.xml
<context:component-scan base-package="com.**.controller"/> <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
<property name="viewResolvers"> <list> <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/pages"/> <property name="suffix" value=".jsp"></property> </bean> </list> </property>
一个controller:
@Controller @RequestMapping("/crop") public class DoCropController { @RequestMapping("/index") public ModelAndView index(){ return new ModelAndView("/crop/index"); } }
在tomcat启动时已经看到spring加载的url映射消息:
2010-04-02 14:51:30,015 INFO [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] - <Mapped URL path [/crop/index] onto handler [com.fel.project.controller.DoCropController@1a59727]> 2010-04-02 14:51:30,015 INFO [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] - <Mapped URL path [/crop/index.*] onto handler [com.fel.project.controller.DoCropController@1a59727]> 2010-04-02 14:51:30,015 INFO [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] - <Mapped URL path [/crop/index/] onto handler [com.fel.project.controller.DoCropController@1a59727]>
但是输入地址http://localhost:8088/springweb/crop/index后总是404的画面,并且报错:
2010-04-02 15:50:41,656 WARN [org.springframework.web.servlet.PageNotFound] - <No mapping found for HTTP request with URI [/springweb/crop/index] in DispatcherServlet with name 'springmvc'>
很不解!有遇到过类似情况的同学请帮下忙。
还有个奇怪的现象,就是用工具生成的controller和模板生成的jsp都能正常找到。
项目骨架是用rapid-framework生成的,然后自己手动加的controller和jsp都报错,查看注解无异常,而且调试时也能跟踪到对应方法中去,
像return new ModelAndView("/crop/index");这句能跟踪到,只是最后报错。