开发者

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

My EJB application looks up some configuration values from JNDI. I would like to be able to change these values and h开发者_高级运维ave 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.

To look up the EventContext or EventDirContext, I've tried this, which numerable examples online advised me to:

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

However, this gives me a 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.

Instead of "", I have tried to look up the exact JNDI names I use, as well as "java:", "java:comp", and "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.

Is it possible to listen for JNDI events, or should I consider a different approach altogether? Appreciate any suggestions.


JNDI event is not supported in GlassFish 3.1.2.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜