Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 228
user1648314 Avatar asked Dec 06 '25 02:12

user1648314


1 Answers

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

like image 193
user1648314 Avatar answered Dec 08 '25 23:12

user1648314



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!