Jboss配置JNDI數據源

一、首先在jboss-as-7.1.1.Final\standalone\configuration\standalone.xml中加入配置。以下:java

 <datasource jndi-name="java:jboss/jdbc/xxx" pool-name="xxx" enabled="true" use-java-context="true">
                    <connection-url>jdbc:jtds:sqlserver://10.20.xxx.xx;databasename=xxx</connection-url>
                    <driver>sqlserver</driver>
                    <security>
                        <user-name>sa</user-name>
                        <password>xxx</password>
                    </security>
               </datasource>

二、而後在jboss-as-7.1.1.Final\modules\net\sourceforge中加入jtds驅動包web

http://pan.baidu.com/s/1tlvBK 需解壓spring

三、在web工程web.xml中加入引用sql

<resource-ref>
		<description>DB Connection</description>
		<res-ref-name>java:jboss/jdbc/xxx</res-ref-name>
		<res-type>javax.sql.DataSource</res-type>
		<res-auth>Container</res-auth>
	</resource-ref>

四、在Spring配置文件中applicationContext.xml 加入app

<bean id="dataSource_xx" class="org.springframework.jndi.JndiObjectFactoryBean">
		<property name="jndiName">
			<value>java:jboss/jdbc/phhs</value>
		</property>
	</bean>

五、而後在引用數據源sqlserver

<bean id="dataSource" class="cn.com.yum.kfc.datasource.util.DynDataSource">      
       <property name="targetDataSources"> 
          <map>
	    <entry key="xx" value-ref="dataSource_xx"/>     
          </map>      
       </property>      
       <property name="defaultTargetDataSource" ref="dataSource_xx"/>      
    </bean>
相關文章
相關標籤/搜索