spring 注解控制器 配置控制器 冲突问题解决?

我最近在旧的项目中增加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"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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">
<context:annotation-config />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>
<context:component-scan base-package="com.test" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/"
p:suffix=".jsp"/>

<bean id="handlerMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
<bean name="/demo.do" class="com.test.DemoController"/>

</beans>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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">
<display-name>demo</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/demo-*.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>demo</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>demo</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>

依据以上的配置测试,如果找demo.do能找到,找test.do就会报告PageNotFound问题?但如果把demo-servlet.xml配置文件去掉demo.do的配置,去掉部分:
<bean id="handlerMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
<bean name="/demo.do" class="com.test.DemoController"/>
在测试的话,test.do就可以找到。
这是冲突呢,还是有什么配置我没有配上?搞不懂

你可能感兴趣的:(spring,mvc,xml,Web,servlet)