81,090
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd" default-autowire="byName" default-lazy-init="true">
<!-- 使用 annotation -->
<context:annotation-config />
<!-- 使用 annotation 自动注册bean,并检查@Controller, @Service, @Repository注解已被注入 -->
<context:component-scan base-package="com.cmcc" />
<!-- spring的属性加载器,加载properties文件中的属性 -->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:config.properties</value>
</property>
<property name="fileEncoding" value="utf-8" />
</bean>
<!-- 数据库配置 -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>com.ibm.db2.jcc.DB2Driver</value>
</property>
<property name="url">
<value>${url}</value>
</property>
<property name="username"><value>${username}</value></property>
<property name="password"><value>${password}</value></property>
<!-- 初始化链接数 -->
<property name="initialSize" ><value>${initialSize}</value></property>
<!-- 连接池可分配最大连接数 -->
<property name="maxActive" ><value>${maxActive}</value></property>
<!-- 池里不会被释放的最多空闲连接数量 -->
<property name="maxIdle" ><value>${maxIdle}</value></property>
<!-- 在不新建连接的条件下,池中保持空闲的最少连接数 -->
<property name="minIdle"><value>${minIdle}</value></property>
<!-- 设置在自动回收超时连接的时候打印连接的超时错误 -->
<property name="logAbandoned" > <value>${logAbandoned}</value> </property>
<!-- 设置自动回收超时连接 -->
<property name="removeAbandoned" ><value>${removeAbandoned}</value> </property>
<!-- 自动回收超时时间(以秒数为单位) -->
<property name="removeAbandonedTimeout"> <value>${removeAbandonedTimeout}</value></property>
<!-- 超时等待时间以毫秒为单位 -->
<property name="maxWait" > <value>${maxWait}</value> </property>
</bean>
<!-- sessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.DB2Dialect
</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<!-- 可以自动创建数据库表(create),不创建(none) -->
<!--<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> -->
<!-- 开启二级缓存 -->
<prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
<!-- 关掉查询时的二级缓存 -->
<prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
<!-- 缓存类 -->
<prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>
</props>
</property>
<!-- 包扫描的方式加载注解类 -->
<property name="packagesToScan">
<list>
<value>${packagesToScan}</value>
</list>
</property>
</bean>
<!--JDBC事务管理器,根据你的情况使用不同的事务管理器,如果工程中有Hibernate,就用Hibernate的事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
<!-- 用注解来实现事务管理 -->
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>