您的位置:首页 > 运维架构 > Tomcat

配置Tomcat JNDI数据源

2017-04-25 00:00 381 查看
1、在tomcat容器中conf/context.xml中配置

<?xml version='1.0' encoding='utf-8'?>

<!-- The contents of this file will be loaded for each web application -->
<Context>

<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>

<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->

<!-- Uncomment this to enable Comet connection tacking (provides events
on session expiration as well as webapp lifecycle) -->
<!--
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
-->
<!--
<Resource
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@127.0.0.1:1521:ORCL"
auth="Container"
maxActive="20"
maxIdle="10"
maxWait="10000"
name="jndi/test1"
type="javax.sql.DataSource"
password="test"
username="test" />
-->
<!-- 使用阿里巴巴的DruidDataSource配置针对Oracle数据库的JNDI数据源 -->
<Resource
name="jndi/test2"
factory="com.alibaba.druid.pool.DruidDataSourceFactory"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8"
password="test"
username="test"
initialSize="20"
minIdle="2"
maxActive="50"
maxWait="10000"
timeBetweenEvictionRunsMillis="60000"
minEvictableIdleTimeMillis="300000"
poolPreparedStatements="false"
maxPoolPreparedStatementPerConnectionSize="20"
removeabandoned="true"
removeabandonedtimeout="60"
logabandoned="false"
filters="stat"/>
</Context>

2、在spring的applicationContext.xml中配置(在spring中集成)

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jndi/test2</value>
</property>
</bean>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: