简体   繁体   English

在Glassfish上侦听JNDI的更改–如何查找EventContext?

[英]Listen for changes in JNDI on Glassfish – how to look up EventContext?

My EJB application looks up some configuration values from JNDI. 我的EJB应用程序从JNDI查找一些配置值。 I would like to be able to change these values and have the application take notice immediately, without having to restart the server or do anything else to trigger it to reconfigure itself. 我希望能够更改这些值并使应用程序立即注意到,而不必重新启动服务器或执行任何其他操作来触发它重新配置自己。

My understanding is that I should implement javax.naming.event.ObjectChangeListener , look up an EventContext or EventDirContext from JNDI, and then call its addNamingListener method to register my ObjectChangeListener . 我的理解是,我应该实现javax.naming.event.ObjectChangeListener ,从JNDI查找EventContextEventDirContext ,然后调用其addNamingListener方法注册我的ObjectChangeListener

To look up the EventContext or EventDirContext, I've tried this, which numerable examples online advised me to: 为了查找EventContext或EventDirContext,我已经尝试过了,在线上的无数示例建议我:

InitialContext ctx = new InitialContext();
EventContext eventContext = (EventContext) ctx.lookup("");

However, this gives me a ClassCastException : 但是,这给了我ClassCastException

java.lang.ClassCastException: com.sun.enterprise.naming.impl.SerialContext cannot be cast to javax.naming.event.EventContext

I also get the equivalent error when I try to cast to EventDirContext . 当我尝试将其EventDirContext转换为EventDirContext时,也会收到同样的错误。

Instead of "", I have tried to look up the exact JNDI names I use, as well as "java:", "java:comp", and "java:comp/env". 我试着查找我使用的确切JNDI名称,而不是“ java:”,“ java:comp”和“ java:comp / env”。 These all return Objects which cannot be cast to any of the event contexts I need. 所有这些返回的对象无法转换为我需要的任何事件上下文。

The JNDI implementation I use is just stock Glassfish 3.1.1. 我使用的JNDI实现只是普通的Glassfish 3.1.1。

Is it possible to listen for JNDI events, or should I consider a different approach altogether? 是否可以收听JNDI事件,或者我应该完全考虑使用其他方法? Appreciate any suggestions. 感谢任何建议。

GlassFish 3.1.2不支持JNDI事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM