项目中使用jboss自带的datasource,可以有两种方式来完成配置(jboss4.2.2+spring2.5):
方式一
1、把jboss安装目录下docs/examples/oracle-ds.xml(此文件夹下不同数据库的数据源配置方式,此为oracle的配置)拷贝到deploy目录下,并修改里面的数据库url、用户名密码,把oracle的驱动放到default/lib下。
2、在自己的web.xml里加上一句
- <resource-ref>
- <res-ref-name>OracleDS</res-ref-name>
- <res-type>javax.sql.DataSource</res-type>
- <res-auth>Container</res-auth>
- </resource-ref>
在WEB-INF下创建文件jboss-web.xml内容如下
- <jboss-web>
- <resource-ref>
- <res-ref-name>OracleDS</res-ref-name>
- <jndi-name>OracleDS</jndi-name>
- </resource-ref>
- </jboss-web>
3、修改spring里的dataSource配置,如下
- <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
- <property name="jndiName">
- <value>OracleDS</value>
- </property>
- </bean>
方式二
1、按方式一中的1进行
2、修改spring配置文件,添加jee空间,具体如下
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:jee="http://www.springframework.org/schema/jee"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
- http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">
- <jee:jndi-lookup id="dataSource" jndi-name="OracleDS" resource-ref="false"/>