How to bridge Spring Application Context events to an other context

前端 未结 5 846
深忆病人
深忆病人 2021-01-07 22:58

I have a Spring web application with two contexts: one (applicationContext) built by ContextLoaderListener and a second (webContext) b

5条回答
  •  粉色の甜心
    2021-01-07 23:20

    I think the actual answer is that you may want to configure your app differently (so that you only have one context) I think in your web.xml you need to do something like this :

    
        example
        org.springframework.web.servlet.DispatcherServlet
        1
        
            contextConfigLocation
                           
                classpath:/META-INF/applicationSpringConfig.xml
            
         
    
    

    But to answer the deeper question. Someone else points out that you can use includes in your spring file (indeed in the above you can have more than one springconfig specified in your dispatcher servlet). But when you include other context files you do not share instances of beans, only definitions.

    Modularising Spring applications has been the only real downside of spring in comparison with EJB etc. That led spring into using OSGi. And the answer to your underlying question of how to share spring context, officially you share spring bean instances between contexts using OSGi (spring dm)

提交回复
热议问题