问题
I have downloaded JBoss EAP 6.1 and I am going to add a new data source. I must bind the data source to a JNDI name. By reading the JNDI name of the sample data source which is:
java:jboss/datasources/ExampleDS
I see that they have used datasources
after java:jboss
. Is this just a naming convention - that I am not able to find anywhere - or would it be fine using java:jboss/bananaboat/MyDS
?`
Is it correct that the first part that is listed below - such as java:comp
is the scope and the rest is just normal hierarchy organization?
java:comp/ - The namespace is scoped to the current component (i.e. EJB)
java:module/ - Scoped to the current module
java:app/ - Scoped to the current application
java:global/ - Scoped to the application server
https://docs.jboss.org/author/display/AS71/JNDI+Reference
回答1:
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
.
回答2:
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.
来源:https://stackoverflow.com/questions/20305180/are-there-jndi-namespace-conventions