How do you share Spring beans between different Spring contexts?

前端 未结 2 1989
谎友^
谎友^ 2021-01-20 01:01

We have an application which uses Spring BlazeDS integration. So far we have just been using Spring and Flex, and it is working fine. We now have a requirement to add some S

相关标签:
2条回答
  • 2021-01-20 01:37

    Create a parent context by using ContextLoaderListener. The DispatcherServlet contexts will automatically become children of that context.

    Create your shared beans in the parent context and refer to them in beans in the child contexts.

    If you are using <component-scan> make sure you don't accidentally scan classes into multiple contexts. See my answer here.

    0 讨论(0)
  • 2021-01-20 02:01

    Add this to your web.xml:

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring/YOUR_APP_CONTEXT.xml</param-value>
    </context-param>
    

    Both beans defined via scanning and direct definitions will be available for your BlazeDS and SpringMVC endpoints.

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