What's the best way to share business object instances between Java web apps using JBoss and Spring? What's the best way to share business object instances between Java web apps using JBoss and Spring? spring spring

What's the best way to share business object instances between Java web apps using JBoss and Spring?


Are the web applications deployed on the same server?

I can't speak for Spring, but it is straightforward to move your business logic in to the EJB tier using Session Beans.

The application organization is straight forward. The Logic goes in to Session Beans, and these Session Beans are bundled within a single jar as an Java EE artifact with a ejb-jar.xml file (in EJB3, this will likely be practically empty).

Then bundle you Entity classes in to a seperate jar file.

Next, you will build each web app in to their own WAR file.

Finally, all of the jars and the wars are bundled in to a Java EE EAR, with the associated application.xml file (again, this will likely be quite minimal, simply enumerating the jars in the EAR).

This EAR is deployed wholesale to the app server.

Each WAR is effectively independent -- their own sessions, there own context paths, etc. But they share the common EJB back end, so you have only a single 2nd level cache.

You also use local references and calling semantic to talk to the EJBs since they're in the same server. No need for remote calls here.

I think this solves quite well the issue you're having, and its is quite straightforward in Java EE 5 with EJB 3.

Also, you can still use Spring for much of your work, as I understand, but I'm not a Spring person so I can not speak to the details.


Terracotta might be a good fit here (disclosure: I am a developer for Terracotta). Terracotta transparently clusters Java objects at the JVM level, and integrates with both Spring and Hibernate. It is free and open source.

As you said, the problem of more than one client web app using an L2 cache is keeping those caches in synch. With Terracotta you can cluster a single Hibernate L2 cache. Each client node works with it's copy of that clustered cache, and Terracotta keeps it in synch. This link explains more.

As for your business objects, you can use Terracotta's Spring integration to cluster your beans - each web app can share clustered bean instances, and Terracotta keeps the clustered state in synch transparently.