Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Configure Spring to Automatically Re-connect to Your EJBs

DZone's Guide to

Configure Spring to Automatically Re-connect to Your EJBs

· Java Zone
Free Resource

Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code! Brought to you in partnership with ZeroTurnaround.

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"
business-interface="us.mikedesjardins.services.MyService"
cache-home="false" lookup-home-on-startup="false"
home-interface="us.mikedesjardins.services.MyService"
resource-ref="false" refresh-home-on-connect-failure="true">
<jee:environment>
<!-- Include any relevant environment settings here -->
</jee:environment>
</jee:remote-slsb>


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

From http://mikedesjardins.us/blog/

The Java Zone is brought to you in partnership with ZeroTurnaround. Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code!

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}