我最近在旧的项目中增加spring的注解控制的配置器,却发现怎么配置都是PageNotFound。然后我把旧的基于配置的控制器删除后,只留下注解的控制器,却能够找到注解的控制器映射,是否两者存在冲突问题,能共存吗?
下面是我的测试代码:
基于注解的控制器:
@Controller
public class TestController {
@RequestMapping("/test.do")
public String test(){
return "test";
}
}
基于配置的控制器:
public class DemoController extends AbstractController{
protected ModelAndView handleRequestInternal(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {
return new ModelAndView("test");
}
}
配置文件
demo-servlet.xml :
<?xml version="1.0" encoding="UTF-8"?>
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
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
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
p:suffix=".jsp"/>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
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">
demo
contextConfigLocation
/WEB-INF/demo-*.xml
org.springframework.web.context.ContextLoaderListener
demo
org.springframework.web.servlet.DispatcherServlet
1
demo
*.do
依据以上的配置测试,如果找demo.do能找到,找test.do就会报告PageNotFound问题?但如果把demo-servlet.xml配置文件去掉demo.do的配置,去掉部分:
在测试的话,test.do就可以找到。
这是冲突呢,还是有什么配置我没有配上?搞不懂