Spring: Well, to have two contexts - web & backend?

I have a spring web application with a spring database. Integration is currently being done in a stupid way of manually copying the .xml backend to web application resources and merges.

I was wondering if Spring is ready to have a bean that will be different ApplicationContext, and whether it can get beans from it; also if it handles bean name conflicts - for example. if I can assign the namespace to "imported" beans.

Or - which is best for this case?

Thanks, Ondra.

+3
source share
3 answers

XML Spring : web, service, persistence. . , ; .

+2

. , ([servlet-name] -context.xml) WebApplicationContext ApplicationContext, , ConfigLocation, ContextLoaderListener. beans, , beans, , , beans .

Web- WebApplicationContext - .. , , ApplicationContext, , xml , , .

<import resource="classpath:dao-context.xml" />
<import resource="classpath:service-context.xml" />
<import resource="security-context.xml" />

. spring - , , [servlet-name] -context.xml -placeholder - , , .

+2

If I understood you correctly, this is definitely good. Some people share database contexts with their online contexts. Example below in your web.xml:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath:someApplicationContext.xml
        classpath:someOtherApplicationContext.xml
    </param-value>
</context-param>

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

As for the collision of beans - you must provide the beans with a unique identifier.

+1
source

Source: https://habr.com/ru/post/1750942/


All Articles