SSH下的Spring配置文件

<?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:p="http://www.springframework.org/schema/p"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">

	<!-- 配置数据源/使用的是druid连接池 -->
	<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
		init-method="init" destroy-method="close">
		<property name="url"
			value="jdbc:mysql://localhost:3306/d_cl_test?characterEncoding=utf8" />
		<property name="username" value="root" />
		<property name="password" value="" />
		<!-- 配置初始化大小、最小、最大 -->
		<property name="initialSize" value="10" />
		<property name="minIdle" value="5" />
		<property name="maxActive" value="150" />
		<!-- 配置获取连接等待超时的时间 -->
		<property name="maxWait" value="30000" />
		<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
		<property name="timeBetweenEvictionRunsMillis" value="5000" />
		<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
		<property name="minEvictableIdleTimeMillis" value="30000" />
		<!-- 用来检测连接是否有效的sql,要求是一个查询语句。如果validationQuery为null,testOnBorrow、testOnReturn、testWhileIdle都不会其作用 -->
		<property name="validationQuery" value="SELECT 'x'" />
		<!-- 建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效 -->
		<property name="testWhileIdle" value="true" />
		<!-- 申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能 -->
		<property name="testOnBorrow" value="false" />
		<!-- 归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能 -->
		<property name="testOnReturn" value="false" />
		<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
		<property name="poolPreparedStatements" value="true" />
		<property name="maxPoolPreparedStatementPerConnectionSize"
			value="100" />
		<!-- 配置监控统计拦截的filters -->
		<property name="filters" value="stat" />
		<!-- 对于建立连接过长的连接强制关闭 -->
		<property name="removeAbandoned" value="true" />
		<!-- 如果连接建立时间超过了1800s,则强制将其关闭(单位s) -->
		<property name="removeAbandonedTimeout" value="1800" />
		<!-- 将当前关闭动作记录到日志 -->
		<property name="logAbandoned" value="true" />
	</bean>

	<!-- 配置SessinFactory -->
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="hibernateProperties">
			<props>
				<!-- <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> -->
				<prop key="hibernate.hbm2ddl.auto">update</prop>
				<prop key="current_session_context_class">thread</prop>
				<prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
				<!-- 关闭hibernate的二级缓存机制 -->
				<prop key="hibernate.cache.use_second_level_cache">false</prop>
				<!-- 数据库连接释放策略:default on_close after_transaction after_statement -->
				<prop key="hibernate.connection.release_mode">after_transaction</prop>
				
				<prop key="hibernate.jdbc.batch_size">100</prop>
			</props>
		</property>
		<property name="mappingLocations">
			<list>
				<value>classpath:/com/go73cl/entity/AirlineCode.hbm.xml</value>
				<value>classpath:/com/go73cl/entity/airlineInfo2.hbm.xml</value>
				<value>classpath:/com/go73cl/entity/Data.hbm.xml</value>
				<value>classpath:/com/go73cl/entity/AirName_AirCode.hbm.xml</value>
				<value>classpath:/com/go73cl/entity/Airport.hbm.xml</value>
				<value>classpath:/com/go73cl/entity/TicketsInfoData.hbm.xml</value>
				<value>classpath:/com/go73cl/entity/CityMap.hbm.xml</value>
			</list>
		</property>
	</bean>

	<!-- ================================ 万恶的分割线 ====================================== -->
	<!-- 声明式事务 -->
	<!-- 配置事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager" p:sessionFactory-ref="sessionFactory" />
	<!--Spring事务拦截器 -->
	<bean id="transactionInterceptor"
		class="org.springframework.transaction.interceptor.TransactionInterceptor">
		<property name="transactionManager" ref="transactionManager" />
		<property name="transactionAttributes">
			<props>
				<!-- 以get/find/load等开头的所有方法采用只读型事务控制类型 -->
				<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
				<!-- 所有方法均进行事务控制,如果当前没有事务,则新建一个事务 -->
				<prop key="*">PROPAGATION_REQUIRED</prop>
			</props>
		</property>
	</bean>
	<!-- 自动代理类 -->
	<bean  id="autoBeanNameProxyCreator"
		class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
		<property name="beanNames">
			<list>
                            <!-- dao层所有以Dao结尾的类 -->
                            <value>*Dao</value>
			</list>
		</property>
		<!-- 这个属性为true时,表示被代理的是目标类本身而不是目标类的接口 -->
		<property name="proxyTargetClass">
			<value>true</value>
		</property>
		<!-- 依赖注入上面定义的事务拦截器transactionInterceptor -->
		<property name="interceptorNames">
			<list>
				<idref local="transactionInterceptor" />
			</list>
		</property>
	</bean>
	<!-- 声明事务管理器的增强 -->
	<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="get*" read-only="true" />
			<tx:method name="*" />
		</tx:attributes>
	</tx:advice>
	<!-- 声明事务管理的切面 -->
	<aop:config>
		<aop:pointcut id="allServiceMethod" expression="execution(* com.go73cl.service.impl.*.*(..))"/>
		<aop:advisor advice-ref="transactionAdvice" pointcut-ref="allServiceMethod"/>
	</aop:config>
</beans>





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值