Search code examples
jakarta-eeglassfishjndi

JNDI lookup fails for Glassfish custom resources


I am new to Java EE 6 and JNDI so please forgive me if my problem seems trivial

I have added a custom resource to Glassfish 3.1.2 JNDI resources via tha admin console:

CommonTasks->Resources->JNDI->Custom Resources

  • JNDI Name: someNumber
  • Resource Type: java.lang.Integer
  • Factory Class: org.glassfish.resources.custom.factory.PrimitivesAndStringFactory
  • Additional Properties: [Name: digit; Value: 6]

Now I wish to look this resource up in my Java EE app I deploy to the glassfish server as ear. I've tried this with no luck:

    InitialContext ctx = new InitialContext();     
    Object o =  ctx.lookup("someNumber");

I keep getting a NameNotFoundException. Can you tell me what is it that I'm doing wrong? I know that you can pass an environment hashtable to the initial context constructor with a provider URL - is this the problem?


Solution

  • Such a rookie mistake.

    Turns out the NameNotFoundException was actually caused by my integer jndi resource not having a value, I was stupid to think that the Additional Properties are custom like in a JMS message and I could look them up later after fetching the object. The "Additional Properties" is were I had to input the "value" property. After making this change everything works smoothly