Are there JNDI namespace conventions?

房东的猫 提交于 2019-12-05 17:57:56
uvsmtid

I had to answer the same question to myself and pulled these links together.

In short, JNDI Naming Policies can be any but JEE defines its own:

JNDI is defined independent of any specific naming and directory service implementation.

However, one important platform that does define a limited set of naming policies for using the JNDI is ... JEE.

This would be the most conventional name for the datasource:

The enterprise namespace is rooted in a URL context for the java URL scheme.

For example, a JDBC Salary database might have the name "java:comp/env/jdbc/Salary".

  • ... comp is bound to a subtree reserved for component-related bindings.
  • ... env is bound to a subtree that is reserved for the component's environment-related bindings, as defined by its deployment descriptor.
  • Resource factory references are placed in subtrees differentiated by their resource manager type.
    • ...jdbc for JDBC DataSource references.

JEE 7 Tutorial also details naming policies to reference EJBs in 32.4.1.1 Portable JNDI Syntax.

Note that @Resource annotation to inject DataSource often specifies JNDI name relative to java:comp/env - see this answer or this answer for portable and deployable solutions.

As mentioned in your updated link, java:jboss namespace is a custom extension provided by WildFly/JBoss only.


To answer the question, the sub-trees under standard namespaces are just normal hierarchy. Obviously, it only makes sense if these sub-trees are (widely) recognized by application server, documentation, processes, etc. Otherwise, I guess nearly flat key-value or random bananaboat/MyDS is fine but still has to be "mounted" under supported namespace like java:jboss.

This is all from memory (I was told by another team member a while ago):

The java: prefix is a JBoss/EE standard. It should be prefixed for all non serializable resources which means they are local to the jvm. After that you can name whatever you like to form the "directory" like structure. e.g. if you use JNDI to get binding "java:jboss/datasources", you will get back a subtree of all resources listed under that name. It will contain ExampleDS and possibly other DataSources as well.

To answer your question: you don't have to name it datasources after java:jboss. But it make sense to name it something meaningful.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!