zoukankan      html  css  js  c++  java
  • springmvc 双亲上下文导致的 No mapping found for HTTP request

    今天搭建spring mvc ,结果发出请求总是No mapping found for HTTP request with URI [******]

    于是开始排查了半天,后来在网上搜到了双亲上下文的概念,

    才知道springmvc的每一个DispatcherServlet都会产生一个WebApplicationContext(子上下文),

    它与Spring初始化生成的WebApplicationContext(父上下文)同时保存在ServletContext中

    而所有的controller对象必须存放在springmvc的子上下文,否则无法找到:No mapping found for HTTP request。

    • 在父上下文中(applicationContext.xml),将Controller的注解排除掉 
    <context:component-scan base-package="com"> 
      <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> 
    </context:component-scan> 

    在springMVC配置文件中只扫描controller

    <context:component-scan base-package="org.apollo.controller">
      <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>  
    </context:component-scan>

    而且如果父上下文中的service配置了事务,则子上下文中不能在扫描service对象,否则会产生service事务失效。

  • 相关阅读:
    线性代数思维导图——3.向量
    微分中值定理的基础题型总结
    构造函数
    Python课程笔记(七)
    0241. Different Ways to Add Parentheses (M)
    0014. Longest Common Prefix (E)
    0013. Roman to Integer (E)
    0011. Container With Most Water (M)
    0010. Regular Expression Matching (H)
    0012. Integer to Roman (M)
  • 原文地址:https://www.cnblogs.com/DajiangDev/p/3967874.html
Copyright © 2011-2022 走看看