flydream36 2008-08-05 15:30
浏览 140
已采纳

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"?>
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就可以找到。
这是冲突呢,还是有什么配置我没有配上?搞不懂

  • 写回答

1条回答 默认 最新

  • iteye_14762 2008-08-05 15:36
    关注

    奇怪, 在论坛中不是给你回答了这个问题吗?
    少配了一个:
    [code="java"][/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图