开发者

What is JNDI and do I need it for website building

开发者 https://www.devze.com 2023-02-10 06:10 出处:网络
I am learning Java and Spring for websites. A few time开发者_如何学编程s I see the word JNDI.

I am learning Java and Spring for websites. A few time开发者_如何学编程s 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?


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.


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消