سؤال

I'm using tomcat. I want put the guava jar and my own jar in tomcat/lib. My jar has a factory to get the event bus and all webapps get access to that factory. I don't know how can I register a listener in webapp1 and post an event from webapp2. The object I'm using in webapp2 doesn't exists in webapp1, I can only share java objects like String, Map of strings etc. but not an object from other webapp.

Some ideas?

هل كانت مفيدة؟

المحلول

this is a classloading issue: most probably, domain classes of webapp1 are not (and should not be) avail in webapp2. believe me, when i say, you don't want to share live objects between webapps.

If you want to share data, consider using a proper JMS(or other similar messaging library), if you want to share behavior, use a REST-service. just to mention the simple common solutions.

all that being said, if you REALLY NEED to go there, you can put the classes you want to share in a single jar and place this and guava in the server-wide classpath + pay extra attention to deployment procedures, as you create a memory-leak. (Still, every time you use that kind of nasty hack, god kills a kitten)

نصائح أخرى

Guava's EventBus is only intended for use with events within a single application. It's definitely not for communication betweens apps or servers (at least not directly). You also definitely shouldn't be relying on the fact that you're currently running both webapps within the same Tomcat instance, since that's something you're likely to want to change at some point. As suggested, a better solution would be a messaging library that's intended for communicating between apps/servers like JMS.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top