第一步:在tomcat6.0的conf文件夹下找到 context.xml 文件 或server.xml文件(区别是应用的范围不同),在<context></context>中加入:
- <Resource name="jdbc/xtaccp" <!-- JNDI名称 -->
- auth="Container" <!-- 此处和web.xml中对应 -->
- type="javax.sql.DataSource" <!-- 数据源类型 -->
- password="root" <!-- 数据库访问密码 -->
- username="a" <!-- 数据库访问用户名 -->
- driverClassName="com.mysql.jdbc.Driver" <!-- 数据库驱动类 -->
- url="jdbc:mysql://localhost:3306/zk" <!-- 数据库访问url -->
- maxActive="100" <!-- 最大活动数 -->
- maxIdle="30"
- maxWait="5000" <!-- 最大等待时间 -->
- />
第二步:在应用程序的web.xml中加入以下代码,配置资源引用
- <resource-ref>
- <res-ref-name>jdbc/demo</res-ref-name>
- <res-type>javax.sql.DataSource</res-type>
- <res-auth>Container</res-auth>
- </resource-ref>
第三步: 在spring配置文件中配置dataSource
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/xtaccp"></property>
<property name="resourceRef" value="true"></property>
</bean>
OK