• 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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?
 
Marshal
Posts: 3149
466
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus 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:


 
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic