Using in spring 3 causes all other views to stop working

前端 未结 3 2075
无人共我
无人共我 2020-12-12 20:33

Simplest example:

I have a dispatcher servlet configured to catch everything:


    dispatcher

        
相关标签:
3条回答
  • 2020-12-12 21:05

    There are 2 problems:

    1. Never use /* in servlet mapping:

      <servlet-mapping> 
          <servlet-name>dispatcher</servlet-name> 
          <url-pattern>/</url-pattern> 
      </servlet-mapping> 
      
    2. <mvc:resources> requires <mvc:annotation-driven> (or explicitly declared handler mappings, etc).

      This happens because DispatcherServlet applies default configuration of handler mappings only when no custom handler mappings found in the context. Since <mvc:resources> adds its own handler mapping, defaults are broken, therefore other handler mappings should be decalred explicitly, either by <mvc:annotation-driven> or manually as beans.

      Also note that <mvc:resources> declares only DefaultAnnotationHandlerMapping and doesn't declare other mappings such as BeanNameUrlHandlerMapping, though they are in defaults of DispatcherServlet. Declare them manually if you need them.

    0 讨论(0)
  • 2020-12-12 21:05

    I also met this problem before. My situation was I didn't put all the 62 spring framework jars into the lib file (spring-framework-4.1.2.RELEASE edition), it did work. And then I also changed the 3.0.xsd into 2.5 or 3.1 for test, it all worked out. Of course, there are also other factors to affect your result.

    0 讨论(0)
  • 2020-12-12 21:27

    add "mvc:annotation-driven" line into view resolvers SpringWeb.XML file. it is work for me

    0 讨论(0)
提交回复
热议问题