3

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.

JoshDM
  • 4,939
  • 7
  • 43
  • 72
Barry S
  • 69
  • 9
  • 1
    If it is in the RestEasy class itself, the static initialization block certainly should be called before any method of the RestEasy class is called. Post your code. – JoshDM Jan 02 '13 at 17:05
  • Let me try to clarify: The other service that RestEasy depends on is a distributed JCS cache. We have 2 instances of JBoss and we need to initialize JCS on both at startup time to enable distributed caching. The static initialization block, which I was trying to use to start JCS, doesn't execute until the RestEasy method is called for the first time. I need JCS to initialize upon JBoss startup. – Barry S Jan 02 '13 at 17:45
  • How are you currently initializing your JCS and how are you currently initializing RestEasy? There are multiple methods to do both, so knowing which you are using should help determine an answer. – JoshDM Jan 02 '13 at 18:54

1 Answers1

1

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.

JoshDM
  • 4,939
  • 7
  • 43
  • 72