Spring - exchange web application context between different webapps

I have a multi-module maven project. One of the modules is the usage level that spring beans has. I want to share with the same spring beans in other modules.

Other modules are deployed as non- related web applications, so ideally my util beans will be singleton, and I will have only one ref for these singleton in all web applications.

I found some links for exchanging spring web application contexts, but it seems that they work in the same .ear, but in my case I have different web applications.

Is there any way to accomplish this?

+4
source share
3 answers

Not easy. Application servers use one class loader for each application, which means that you will get a ClassCastException , even if you manage to pass the link from the one that created the beans to another.

You need to define beans at the time the application server starts. Put the beans code in the classpath of the application server and check your documentation for setting up the JNDI context. The JNDI context allows the sharing of global resources (such as database connections).

+4
source

I assume you mean methods like this . As far as I know, this should be possible outside the EAR. But there is no official standard for this. In practice, you need to make sure that the Spring JAR files are loaded into the general context loader for your servlet container, and not in the context of individual applications. I believe that the XML file should also be in this path of the parent context class.

+2
source

Depending on the application server / servlet container, you can use Google for sharing methods of ServletContext between webapps. WebApplicationContext is stored in ServletContext, so you get a response.

0
source

All Articles