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: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-3.0.xsd
      http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context-3.0.xsd
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
     http://www.springframework.org/schema/tx  http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    ">


	<!-- 配置SessionFactory -->
	<context:component-scan base-package="com.shop" />
	<!--  
	<context:property-placeholder location="classpath:MySqljdbc.properties" />
	-->
	<context:property-placeholder location="classpath:SQLjdbc.properties" />
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<property name="driverClassName" value="${driverClass}" />
		<property name="url" value="${jdbcUrl}" />
		<property name="username" value="${user}" />
		<property name="password" value="${password}" />
		<!-- 连接池启动时的初始值 -->
		<property name="initialSize" value="1" />
		<!-- 连接池的最大值 -->
		<property name="maxActive" value="500" />
		<!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 -->
		<property name="maxIdle" value="2" />
		<!--  最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,n以免洪峰来时来不及申请 -->
		<property name="minIdle" value="1" />
	</bean>

	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="mappingDirectoryLocations">
			<list>
				<value>classpath:/com/shop/vo</value>
			</list>
		</property>

		<property name="hibernateProperties">
			<value>
				hibernate.dialect=org.hibernate.dialect.SQLServerDialect
				<!--hibernate.dialect=org.hibernate.dialect.MySQLDialect-->
				hibernate.hbm2ddl.auto=create
				hibernate.show_sql=true
				hibernate.format_sql=true
				<!--
					配置缓存Cache hibernate.current_session_context_class=thread
					hibernate.cache.use_second_level_cache=true
					hibernate.cache.use_query_cache=true
					hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
				-->
				hibernate.cache.use_second_level_cache=true
				hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
				hibernate.cache.use_query_cache=true
			</value>
		</property>
		<!--
			<property name="cacheQueries"> <value>true</value> </property>
		-->
	</bean>
	<!-- 配置事务管理器 -->
	<bean id="txManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>

	<!-- 事务的传播特性 -->
	<tx:advice id="txAdvice" transaction-manager="txManager">
		<tx:attributes>
			<tx:method name="add*" propagation="REQUIRED" />
			<tx:method name="del*" propagation="REQUIRED" />
			<tx:method name="update*" propagation="REQUIRED" />
			<tx:method name="save*" propagation="REQUIRED" />
			<tx:method name="load*" propagation="REQUIRED" />
		</tx:attributes>
	</tx:advice>

	<!-- 那些类那些方法使用事务 -->

	<aop:config>
		<aop:pointcut id="allManagerMethod" expression="execution(* com.shop.dao..*.*(..))" />
		<aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod" />
	</aop:config>
</beans>

相关推荐