1、首先在jboss-as-7.1.1.Final\standalone\configuration\standalone.xml中加入配置。如下:
<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>
2、然后在jboss-as-7.1.1.Final\modules\net\sourceforge中加入jtds驱动包
http://pan.baidu.com/s/1tlvBK 需解压
3、在web工程web.xml中加入引用
<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>
4、在Spring配置文件中applicationContext.xml 加入
<bean id="dataSource_xx" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:jboss/jdbc/phhs</value>
</property>
</bean>
5、然后在引用数据源
<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>