在Tomcat下使用,jndi名称需要这么写:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/myJndiName"></property>
</bean>
在Weblogic下使用,jndi名称是这么写:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="myJndiName"></property>
</bean>
由于jndi名称写法不一致,以前的做法都是在不同的服务器动态切换配置文件,比较麻烦
刚刚发现,其实可以这么写,就不用切换了,哈哈:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="myJndiName"></property>
<property name="resourceRef" value="true"></property>
</bean>
添加了一个属性resourceRef,api上的解释是这样的:Set whether the lookup occurs in a J2EE container, i.e. if the prefix "java:comp/env/" needs to be added if the JNDI name doesn't already contain it. Default is "false".
本文介绍了一种在不同服务器间通用的JNDI配置方法,通过设置resourceRef属性为true,可自动适配Tomcat和Weblogic等服务器的JNDI前缀,避免了动态切换配置文件的繁琐。
4790

被折叠的 条评论
为什么被折叠?



