1

I'm running a web-server (Embedded Jetty) that hosts multiple WARs and also supports hot deployment of new\exisitng webapps (as described here).

I have a set of common beans which needs to be shared (same instance) between the different web-apps. Is it possible to use Spring to somehow handle this beans?

Found this excellent explanation, but it explain how to do it with EAR files, which is not an option on my side since as I mentioned we support hot deployment of new WARs, we don't want to redeploy all the web-apps when deploying one web-app.

Is it possible to use Spring to handle these beans? or do I need to create some kind of wrapper in my common-beans to behave as a singleton (all web-apps runs on the same JVM)

LiranBo
  • 2,054
  • 2
  • 23
  • 39
  • If it isn't a single application (an EAR) you cannot (and shouldn't) share beans. – M. Deinum Apr 11 '19 at 09:43
  • I don't agree with u, I've seen many use cases where this design applies (such as the provided link). This is not a nice to have requirement on my side, I need this to work, and I know I can make it work using simple Java singleton, I'm wondering if Spring can provide the same functionality as well. It's either that or use a factory.. – LiranBo Apr 11 '19 at 11:21
  • The link is a single application, the EAR... Which is split in several modules (WARS). Deploying individual WARS deploys individual application. As long as they aren't grouped in a single EAR it will not work. Nor should you as eventually you will run into binary incompatiblities, unless you always deploy everything. Why do you want to share a bean in the first place? Looks like you are trying to solve something with the wrong thing. Also what has this to do with Embedded Jetty? Looks like regular Jetty to me. – M. Deinum Apr 11 '19 at 11:24
  • We are running a spark application that hosts multiple web-apps (this is why embedded jetty is used as the container). The reason we want to share the bean is because we want to share the sparkSession (so we can also share the same resources), this is also a requirement by Spark - One JVM -> One SparkSession. We already have a working code that packs everything together, but we want to split it - mainly to improve our deployment abilities. – LiranBo Apr 11 '19 at 11:42
  • You might want to add the fact that you are using Spark, as that is quite significant and is missing from the original question. It looks also specific to Spark and I'm not sure if you can share the same session over different webapps (I don't have spark knowledge). – M. Deinum Apr 11 '19 at 11:45

0 Answers0