applicationContext.xml配置

前端之家收集整理的这篇文章主要介绍了applicationContext.xml配置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<?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"
	xmlns:beans="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p"
	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/tx 
                                                       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                                                       http://www.springframework.org/schema/aop
                                                       http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">
	<context:property-placeholder location="classpath:config/jdbc.properties" />
	<!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
		destroy-method="close"> <property name="driverClassName" value="${jdbc.driver}" 
		/> <property name="url" value="${jdbc.url}" /> <property name="username" 
		value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" 
		/> <property name="maxWait" value="20000"></property> <property name="maxActive"><value>20</value></property> 
		<property name="maxIdle"><value>20</value></property> <property name="minIdle"><value>3</value></property> 
		<property name="minEvictableIdleTimeMillis" value="120000"></property> <property 
		name="removeAbandoned" value="true" /> <property name="removeAbandonedTimeout"><value>500</value></property> 
		<property name="testWhileIdle" value="true" /> <property name="testOnBorrow"><value>false</value></property> 
		<property name="testOnReturn"><value>false</value></property> <property name="validationQuery"><value>select 
		sysdate from dual</value></property> <property name="timeBetweenEvictionRunsMillis"><value>30000</value></property> 
		<property name="numTestsPerEvictionRun"><value>20</value></property> </bean> -->


	<bean id="master" class="com.mchange.v2.c3p0.ComboPooledDataSource"
		destroy-method="close">
		<property name="driverClass" value="${jdbc.driver}" />
		<property name="jdbcUrl" value="${jdbc.url.w}" />
		<property name="user" value="${jdbc.username.w}" />
		<property name="password" value="${jdbc.password.w}" />
		<property name="minPoolSize" value="${jdbc.miniPoolSize}" />
		<property name="maxPoolSize" value="${jdbc.maxPoolSize}" />
		<property name="initialPoolSize" value="${jdbc.initialPoolSize}" />
		<property name="maxIdleTime" value="${jdbc.maxIdleTime}" />
		<property name="acquireIncrement" value="${jdbc.acquireIncrement}" />
		<property name="acquireRetryAttempts" value="${jdbc.acquireRetryAttempts}" />
		<property name="acquireRetryDelay" value="${jdbc.acquireRetryDelay}" />
		<property name="testConnectionOnCheckin" value="${jdbc.testConnectionOnCheckin}" />
		<property name="automaticTestTable" value="${jdbc.automaticTestTable}" />
		<property name="idleConnectionTestPeriod" value="${jdbc.idleConnectionTestPeriod}" />
		<property name="checkoutTimeout" value="${jdbc.checkoutTimeout}" />
	</bean>
	<bean id="slave" class="com.mchange.v2.c3p0.ComboPooledDataSource"
		destroy-method="close">
		<property name="driverClass" value="${jdbc.driver}" />
		<property name="jdbcUrl" value="${jdbc.url.r}" />
		<property name="user" value="${jdbc.username.r}" />
		<property name="password" value="${jdbc.password.r}" />
		<property name="minPoolSize" value="${jdbc.miniPoolSize}" />
		<property name="maxPoolSize" value="${jdbc.maxPoolSize}" />
		<property name="initialPoolSize" value="${jdbc.initialPoolSize}" />
		<property name="maxIdleTime" value="${jdbc.maxIdleTime}" />
		<property name="acquireIncrement" value="${jdbc.acquireIncrement}" />
		<property name="acquireRetryAttempts" value="${jdbc.acquireRetryAttempts}" />
		<property name="acquireRetryDelay" value="${jdbc.acquireRetryDelay}" />
		<property name="testConnectionOnCheckin" value="${jdbc.testConnectionOnCheckin}" />
		<property name="automaticTestTable" value="${jdbc.automaticTestTable}" />
		<property name="idleConnectionTestPeriod" value="${jdbc.idleConnectionTestPeriod}" />
		<property name="checkoutTimeout" value="${jdbc.checkoutTimeout}" />
	</bean>
	<beans:bean id="myDataSource"
		class="com.xb.core.datasource.ReplicationDataSource">
		<property name="targetDataSources">
			<map key-type="java.lang.String">
				<!-- write -->
				<entry key="master" value-ref="master" />
				<!-- read -->
				<entry key="slave" value-ref="slave" />
			</map>
		</property>
		<property name="defaultTargetDataSource" ref="master" />
		<!--<property name="dataWrite" ref="dataSourceW" /> <property name="dataRead" 
			ref="dataSourceR"/> <list> <ref bean="dataSource2" /> <ref bean="dataSource3" 
			/> </list> </property> -->
	</beans:bean>
	<!-- sqlSessionfactorybean是用于创建sqlSessionFactory -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.sqlSessionfactorybean">
		<property name="dataSource" ref="myDataSource" />
		<property name="mapperLocations" value="classpath:com/xb/mapper/*.xml" />
		<property name="typeAliasesPackage" value="com.xb.model" />
	</bean>

	<!-- 自动扫描包的方式 来注册Mapper -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.xb.dao" />
	</bean>
	<!-- 配置需要被Spring管理的Bean(创建,创建后放在了Spring IOC容器里面) -->
	<!-- 自动扫描dao和service和 action包(自动注入) -->
	<context:component-scan base-package="com.xb"
		use-default-filters="false">
		<!-- 扫描符合@Service @Repository @Controller的类 -->
		<context:include-filter type="annotation"
			expression="org.springframework.stereotype.Service" />
		<context:include-filter type="annotation"
			expression="org.springframework.stereotype.Repository" />
		<context:include-filter type="annotation"
			expression="org.springframework.stereotype.Controller" />
	</context:component-scan>
	<!-- 该 BeanPostProcessor 将自动对标注 @Autowired 的 Bean 进行注入 -->
	<bean
		class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
	<!-- 1.注解方式配置事务 -->
	<!-- 开启注解配置 -->
	<context:annotation-config />
	<!-- 开启事务注解驱动 -->
	<tx:annotation-driven />
	<!-- 事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="myDataSource" />
	</bean>
	<aop:aspectj-autoproxy proxy-target-class="true" />
	<beans:bean id="replicationDataSourceAspect"
		class="com.xb.core.datasource.ReplicationDataSourceAspect" />
	<aop:config>
		<aop:aspect id="c" ref="replicationDataSourceAspect">
			<aop:pointcut id="mapperTx" expression="execution(* com.xb.service.*.*.*(..))" />
			<aop:before pointcut-ref="mapperTx" method="before" />
		</aop:aspect>
	</aop:config>
	
</beans>
原文链接:/xml/294179.html

猜你在找的XML相关文章