web-servicesjbossresteasyjcs

How to initialize RestEasy web service after JBoss starts


I have a RestEasy web service that is deployed to JBoss 7.1.1. The web service has a dependency on another service. This other service must be initialized upon JBoss startup -- before the RestEasy web service is called for the first time. I tried using a static initialization block inside of the RestEasy class, but that won't get executed until one of the RestEasy web service methods is called for the first time.

I would appreciate any suggestions on how initialize the dependent service (upon JBoss startup) before any RestEasy method is called.


Solution

  • If your static block isn't working properly, you can initialize your second service by calling a listener class in your web.xml that references your second service instance.

    <listener>
        <description>Initializes the Second Service</description>
        <display-name>Second Service Loader</display-name>
        <listener-class>my.package.path.SecondServiceListener</listener-class>
    </listener>
    

    Alternately, if you're using Spring, the solution is even more simple. Please elaborate on your environment.