Search code examples
jax-rslifecycle

lifecycle callbacks for JAX-RS resources?


suppose i have a jax-rs resource class that looks like this:

@Path("/nodes")
public class NodeResource { 
   //Temp - those injections should work
   @EJB
   ListNodesLocal nodeList;
   //stuff
}

and i want some sort of lifecycle callback so i can manually lookup that field via JNDI because injection isnt working for me yet (using jboss 6 m5. see this issue : https://jira.jboss.org/browse/JBAS-8575). ideally im looking for something like

@PostConstruct
private void init() {
    //manual JNDI to come here
}

can i do this somehow ? i've tried javax.annotation.PostConstruct to no avail. is there something that works?


Solution

  • Since you linked to jboss in your question this answer assumes you're using the Resteasy implementation of JAX-RS. You can register interceptors to hook into the lifecycle. See here. That's how I was able to use Shiro annotations to authorize clients who want to invoke my API.