简体   繁体   中英

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 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 .

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.

GlassFish 3.1.2不支持JNDI事件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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