JAX-RS 资源的生命周期回调?
假设我有一个 jax-rs 资源类,如下所示:
@Path("/nodes")
public class NodeResource {
//Temp - those injections should work
@EJB
ListNodesLocal nodeList;
//stuff
}
并且我想要某种生命周期回调,以便我可以通过 JNDI 手动查找该字段,因为注入对我来说还不起作用(使用 jboss 6 m5。请参阅此问题:https://jira.jboss.org/browse/JBAS-8575)。 理想情况下,我正在寻找类似的东西,
@PostConstruct
private void init() {
//manual JNDI to come here
}
我可以以某种方式做到这一点吗?我尝试过 javax.annotation.PostConstruct 无济于事。有什么有效的方法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您在问题中链接到 jboss,所以这个答案假设您正在使用 JAX-RS 的 Resteasy 实现。您可以注册拦截器来挂钩生命周期。请参阅此处。这就是我如何使用 Shiro 注释来授权想要调用我的 API 的客户端。
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.