1.将数据库 驱动jar 放到 tomcat / lib 下。
2.MET-INF 下新建 content.xml 文件。
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="jdbc/timesshDB"
auth="Container"
type="javax.sql.DataSource"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
testWhileIdle="true"
testOnBorrow="true"
testOnReturn="false"
validationQuery="SELECT 1"
validationInterval="30000"
timeBetweenEvictionRunsMillis="30000"
maxActive="100"
minIdle="10"
maxWait="10000"
initialSize="10"
removeAbandonedTimeout="60"
removeAbandoned="true"
logAbandoned="true"
minEvictableIdleTimeMillis="30000"
jmxEnabled="true"
jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
username="root"
password="root"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://192.168.101.231:3306/timessh?autoReconnect=true&autoReconnectForPools=true&failOverReadOnly=false&useUnicode=true&characterEncoding=utf-8"/>
</Context>
3 spring.xml 配置文件 中:
<bean id="dataSourceTimessh" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/timesshDB" />
</bean>
<bean id="sessionFactoryTimessh"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSourceTimessh" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<!-- 是否在后台显示sql,开发中显示,上线后关闭 -->
<prop key="hibernate.show_sql">false</prop>
<!-- 批量操作 -->
<prop key="hibernate.jdbc.batch_size">10</prop>
<prop key="hibernate.query.factory_class">
org.hibernate.hql.ast.ASTQueryTranslatorFactory
</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>com.experience.common.db.po.timesshdb</value>
</list>
</property>
</bean>