`
happyqing
  • 浏览: 3151959 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

spring下jndi配置的问题

阅读更多

在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".

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics