0

I have a web application trying to access a JNDI declared in WebSphere Application Server. The JNDI is declared under Object pool managers. However, I'm receiving an error when I access the pool. The error says that comp/env/pool is not found in context "java:".

My code is written as follows:

InitialContext initialContext = new InitialContext();
ObjectPoolManager opm = (ObjectPoolManager)initialContext.lookup("java:comp/env/pool");

Accessing the pool via the code below works:

ObjectPoolManager opm = (ObjectPoolManager)initialContext.lookup("pool");

I'm confused because according to what I've found on the internet, java:comp/env/ is a default prefix for JNDI. So why does it cause an error in my case?

Thank you!

Arci
  • 6,647
  • 20
  • 70
  • 98

1 Answers1

0

you can only use java:comp/env if you have declared a reference to the Object Pool in your web.xml under the resource-ref section.

See What is resource-ref in web.xml used for? for further explanation.

Community
  • 1
  • 1
DanielBarbarian
  • 5,093
  • 12
  • 35
  • 44