I am learning Java and Spring for websites. A few times I see the word JNDI. What is it and do I need to learn it or do I need it in the process of building a web application?
2 Answers
JNDI is a convenient way for an application to say "I need resource X" and for container (e.g. Tomcat) to say "resource X is available, look here or there where X is actually configured".
You could use above mechanism to avoid, for example, hardcoding database properties in your code. You could achieve the same by having a configuration file, but some contexts (e.g.: .war files) configuration files are not persisted between redeployments so they are not an option.
Good examples on what is being bound to JNDI would be database data sources, references to SMTP email servers, security realms and so on.
Think of JNDI as a HashMap
where key is a String
and value is either a concrete object or another HashMap
of the same structure. So locating a value like jndi://a/b
would resolve to going to the top-level map, finding key a
and expecting it's value to be another map. Then key b
would be looked up in that sub-map and relevant value returned to the user.

- 26,463
- 15
- 97
- 154
The Java Naming and Directory Interface (JNDI) is a Java API for a directory service that allows Java software clients to discover and look up data and objects via a name. Like all Java APIs that interface with host systems, JNDI is independent of the underlying implementation. May be you can use it but i have never gave it a try!

- 459
- 8
- 22