我已经下载了 JBoss EAP 6.1,我要添加一个新的数据源。我必须将数据源绑定(bind)到 JNDI 名称。通过读取示例数据源的 JNDI 名称,它是:
java:jboss/datasources/ExampleDS
我看到他们在java:jboss
之后使用了datasources
。这只是一个命名约定 - 我无法在任何地方找到 - 或者使用 java:jboss/bananaboat/MyDS
会很好吗?`
下面列出的第一部分是否正确 - 例如 java:comp
是范围,其余部分只是正常的层次结构组织?
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
最佳答案
我必须自己回答同一个问题并将这些链接放在一起。
简而言之, JNDI Naming Policies 可以是任何但 JEE 定义了它自己的:
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.
这将是数据源最常规的名称:
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 教程还详细说明了在 32.4.1.1 Portable JNDI Syntax 中引用 EJB 的命名策略。
请注意,用于注入(inject) DataSource
的 @Resource
注释通常指定相对于 java:comp/env
的 JNDI 名称 - 参见 this answer 或 this answer 可移植和可部署的解决方案。
如your updated link所述,java:jboss
命名空间是仅由WildFly/JBoss 提供的自定义扩展。
要回答这个问题,标准 namespace 下的子树只是普通层次结构。显然,只有当这些子树被应用程序服务器、文档、进程等(广泛)识别时才有意义。否则,我想几乎平坦的键值或随机 bananaboat/MyDS
是好的,但仍然必须在支持的命名空间下“安装”,例如 java:jboss
。
关于java - 有 JNDI namespace 约定吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20305180/