Configuring / searching JNDI in Glassfish

I'm having trouble getting the basic JNDI configuration in Glassfish.

I have something that I think should be a simple task: at runtime, determine if a particular property is set to true or not. I think this is a good JNDI application, but it seems it cannot find the correct path between the application server and the servlet code.

This is how I set up the property in Glassfish:

enter image description here

In my servlet code, I am trying to find the value with:

Boolean enabled = (Boolean) ctx.lookup("java:global/arizona/quartz_enabled"); 

In addition to this path, I also tried the following without success:

  • Java: global / arizona / arizona / quartz_enabled
  • Java: module / arizona / quartz_enabled
  • Java: module / arizona / arizona / quartz_enabled

My application is called Arizona, but it deploys in the root context, if that matters.

I'm sure it's just a matter of determining the right namespace to achieve the property, but I feel like I'm just shooting in the dark trying to find it. Is there an easy way to view the JNDI tree in Glassfish?

+7
source share
3 answers

When searching for the JNDI resource created on the server, that JNDI name is exactly what you entered as the name on the server. IE:

Boolean enabled = (Boolean) ctx.lookup ("Arizona");

For JNDI naming conventions and some code examples on how to view everything, see this page:

http://www.javaworld.com/javaworld/jw-01-2000/jw-01-howto.html

+3
source

In such situations, I simply place a breakpoint where the object ( InitialContext in this case) is created and then evaluates it. IntelliJ IDEA is a good appraiser , not sure about other, possibly low-level IDEs.

Btw, the correct prefix for all Java EE bindings is java:comp/env/ , for example. java:comp/env/arizona/quartz_enabled .

You can also see this resource .

0
source

I can't get it to work with javax.naming.InitialContext#lookup , but inserting the resource with

 @Resource(name = "arizona/quartz_enabled") private Boolean enabled; 

works great.

0
source

All Articles