• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Accessing global naming resources via annotations

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following entries in my Tomcat 9.0 server.xml:

In my web application, I have the following configured in web.xml:

I have defined a ServletContextListener roughly as follows:

The code runs, and when it does, the println() statements correctly print out the values from the web application's web.xml and the server's server.xml. Furthermore, when I inspect the environmentContext variable during debugging, I can see both environment entries.

The problem comes when I comment out the @Resource annotation on the dataDirectory property. The application fails to start with this message:

javax.naming.NameNotFoundException: Name [DataDirectory] is not bound in this Context. Unable to find [DataDirectory].

What is it about global naming resources that prevents me from using the @Resource annotation?
 
Saloon Keeper
Posts: 2754
359
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Kevin Dean wrote:The problem comes when I comment out the @Resource annotation on the dataDirectory property


Are you commenting-out the entry in the server.xml file or the @Resource annotation in your Java code?
 
Kevin Dean
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:

Kevin Dean wrote:The problem comes when I comment out the @Resource annotation on the dataDirectory property


Are you commenting-out the entry in the server.xml file or the @Resource annotation in your Java code?



Sorry, that should read "when I uncomment", not "when I comment out". I remove the comment before the @Resource annotation in the Java source and the app fails on startup.
 
Kevin Dean
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my original post, I forgot to include that I have this entry in my server.xml as well:


 
It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!