English 中文(简体)
Naming and Directory (JNDI) - What are Pitfalls for Using JNDI
原标题:
  • 时间:2009-12-04 12:30:29
  •  标签:
  • java
  • jndi

Naming and Directory (JNDI) - What are Pitfalls for Using JNDI

问题回答

The question is a bit vague, but here are a few points to consider and that relates to JNDI.

  1. the benefit of JNDI is that object creation is decoupled from object lookup
  2. direct lookup in JDNI impede testability, prefer injection if possible
  3. if you still use direct lookup, you will need to mock JNDI either yourself or by using a file-system implementation
  4. beware classloader issue if you use it in app. server
  5. the parameters used in ObjectFactory are somehow obscure if you plan to implement your own object factory (context, environment, etc.)
  6. each JVM has its own JNDI. When a client looks up a remote EJB, a special factory is used that returns a remote reference to the EJB, but the JNDI is itself local. (Note that there exist clustered JNDI implementation but I have no experience with it).
  7. Naming of EJBs will depend from app. server
  8. Global and local JNDI is always a source of confusion
  9. I ve never seen anybody searching a JNDI directory, only example of lookup

I used JDNI to implement Custom Resource in Glassfish and that was OK. But I found JNDI to be a frequent source of confusion.

Here is my top three:

  1. Lacking documentation
  2. half-hearted API
  3. Haven t found anyone using it besides app servers

There are a couple of tutorials how to use JNDI but most of the time, you ll be stuck when something goes wrong. The implementation also frowns upon useful error messages. If a key can t be found, then you just get the innermost key name - the path which lead to the key is missing.

There is also no way to navigate the JNDI hierarchy. What s the point of having a hierarchy with parent and children when you can t navigate it?

And what about java:comp/env? Why is it there? When can I omit it? When do I have to use it? Has anyone ever added a tree which doesn t start with java:?





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签