spring数据源使用jndi
1:applicationContext.xml中配置如下:
?
加入属性描述文件
?
?<bean id="propertyConfigurer"
??????? class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
??? <property name="location">
????? <value>/WEB-INF/applicationContext.properties</value>
??? </property>
??? <property name="fileEncoding">
????? <value>GBK</value>
??? </property>
? </bean>
?
?
配置jndi数据源
?
<bean id="dataSource.FBCM"
??????? class="org.springframework.jndi.JndiObjectFactoryBean">
??? <property name="jndiName">
????? <value>${jndi.oradata}</value> (为在属性文件中定义的jndi数据源哦)
??? </property>
? </bean>
?
2:applicationContext.properties中定义jndi数据源如下:
?
#################数据库连接参数
#ORACLE数据库连接JNDI名称。weblogic下为nstc/jdbc/OraData;tomcat下#java:comp/env/nstc/jdbc/OraData
jndi.oradata=java:comp/env/jdbc/WebData
?
?
3:在web.xml中配置
?
??? <resource-ref>??
??? <description>DB Connection</description>??
??? <res-ref-name>jdbc/WebData</res-ref-name>??
??? <res-type>javax.sql.DataSource</res-type>??
??? <res-auth>Container</res-auth>??
</resource-ref>
?
注释:如果只有一个数据源时,不在web.xml中配置不会出错
???????? 但是如果有多个数据源时,必须在web.xml中配置,不然找不到