Mike Desjardins is an Enterprise Java developer who lives in Portland, Maine, U.S.A. His primary focus is on ORM technologies, Database Design, and Web Services, as well as occasional dabbling in web design. Mike is also a proud parent and avid gardener. Mike is a DZone MVB and is not an employee of DZone and has posted 6 posts at DZone. You can read more from them at their website. View Full User Profile

Configure Spring to Automatically Re-connect to Your EJBs

  • submit to reddit
If you have a service that is a client of a remote EJB, you may have run into the situation where the EJB server shuts down and restarts. When this happens your EJB client may need to be restarted as well, in order to re-discover and reconnect to the EJBs; otherwise you'll end up with connection exceptions in the client.

If you're using Spring to autowire your EJB clients, it's quite easy to configure the service so that the home interface will refresh on connection failures. Note that if you're using EJB3, you will need to upgrade to at least version 2.5.5 of Spring. There is a bug in earlier versions of Spring which prevented this technique from working with EJB3.

In your spring file, make sure you configure your slsb references to have cache-home disabled, and refresh-home-0n-connect-failure thusly:

<jee:remote-slsb id="myService" jndi-name="MyService/remote"
cache-home="false" lookup-home-on-startup="false"
resource-ref="false" refresh-home-on-connect-failure="true">
<!-- Include any relevant environment settings here -->

With this, you should be able to restart your EJB hosts without needing to restart your EJB clients!

From http://mikedesjardins.us/blog/

Your rating: None
Published at DZone with permission of Mike Desjardins, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Andrew McVeigh replied on Tue, 2008/10/28 - 9:23am

it's a nice feature. how does it work under the covers? does it place in some form of proxy/interceptor to handle the reconnection?


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.