Spring MVC Annotations with Global Context context:component-scan?

后端 未结 1 1605
野的像风
野的像风 2021-01-06 17:50

I have a spring dispatcher servlet with servlet-name \"spring-mvc\". The spring-mvc-servlet.xml appears as follows:



        
1条回答
  •  一个人的身影
    2021-01-06 18:30

    You can load your contexts hierarchically so that context described in annotation-context.xml becomes a parent of your Spring MVC context. The latter will then be able to access all the beans defines in the former.

    Spring documenation describes several ways to do it. For example, in your web.xml:

    // load parent context
    
      contextConfigLocation
      /WEB-INF/annotation-context.xml
    
    
    
      org.springframework.web.context.ContextLoaderListener
    
    
    // load Spring MVC context
    
      spring-mvc
      org.springframework.web.servlet.DispatcherServlet
      1
    
    

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