打开tomcat目录下的conf目录,编辑sever.xml目录。在<GlobalNamingResources>标签中添加数据源配置:
<Resource
name="jdbc/dbsourse"
scope="Shareable"
type="javax.sql.DataSource"
factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
url="jdbc:oracle:thin:@172.16.200.9:1521:orcl"
driverClassName ="oracle.jdbc.OracleDriver"
username="username"
password="password"
/>
编辑同目录下的context.xml。 在<Context> 标签中添加数据源连接:
<ResourceLink global="jdbc/dbsourse" name="jdbc/dbsourse" type="javax.sql.DataSource" />
<bean id="dataSource" name="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/dbsourse" />
</bean>