Is there a way to share an app-context between two deployed wars? One war needs to wire-in the services of another, and I don't know where to start with this.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
There is an informative blog post I think you should check out: Using a shared parent application context in a multi-war Spring application
Agreed with @RichardSmith, the accepted answer was not helpful for me. While Richard's answer was helpful in pointing me in the right direction, I'm using Jetty so I can't use EAR. I ended up using the server context to share an object(s) between wars - works even with hot-(re)deployed webapps:
https://stackoverflow.com/a/46968645/1287091
Probably a way to adapt this for Tomcat as well.
The general purpose of a web application container like tomcat is that each application is able to run independently (so you can stop and start individual apps without affecting others), which means that there has probably been a lot of effort put into their development specifically to prevent you from doing this. So even if you find a loophole, I would suggest against using it unless it is recommended or at least sanctioned by the designers.
I suggest you start looking for other solutions. For example:
You could possibly bind a context to JNDI if it doesn't exist.
The price for this is that each webapp's context somehow has to be aware that it might not be the primary.
Also, you need to be really careful about race conditions, e.g.
There is maybe a way if you start an embedded jetty server and access both web apps from the class where you start and configure the jetty server.
See:
Embedding Jetty
Do you need to share the runtime context, or do you want to just re-use bean definitions across the two applications?
If it is only the latter then you could easily extract the common Spring context XML files into some shared dependency, and just re-use the JAR across the two webapps. However if you need the beans/services in each application to talk to each other, you need a different option.