动态传递JNDI名称 [英] Passing the JNDI name dynamically
问题描述
我有很多Web连接服务器,它们的数据库连接使用不同的JNDI名称,因此我必须为每个服务器构建许多Ears文件.我想做这样的事情:
I have a lot of Websphere servers with different JNDI name of my DB connection so I have to build many ears files for each server. I'd like to do something like this:
<bean id="dbDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${SPECIFIC_JNDI_NAME}"/>
</bean>
如何创建此SPECIFIC_JNDI_NAME变量?
How can I create this SPECIFIC_JNDI_NAME variable?
推荐答案
正确的Java EE方法是在代码中使用资源引用,例如:java:comp/env/jdbc/myDSRef
,然后在执行过程中将此资源引用绑定到实际的JNDI名称安装过程.
The proper Java EE way to do it, is using resource references in your code like: java:comp/env/jdbc/myDSRef
, then this resource reference is bind to actual JNDI name during the installation process.
您可以通过@Resource
标记定义引用,也可以在部署描述符中输入条目(web.xml
或ejb-jar.xml
).
You either define references via @Resource
tag, or entry in the deployment descriptor (web.xml
or ejb-jar.xml
).
您可以通过管理控制台,wsadmin
安装脚本或放置在WEB-INF文件夹中的ibm-web-bnd.xml
文件将其映射到JNDI名称.
You map it to the JNDI name via admin console, wsadmin
installation script, or ibm-web-bnd.xml
file placed in the WEB-INF folder.
可以在Spring中使用引用.
It is possible to use references with Spring.
这篇关于动态传递JNDI名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!