Maven+Mybatis+Spring配置之第二步:配置Spring

1.配置Datasource:
<bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource"
	destroy-method="close">
	<property name="driverClass" value="${jdbc.driverClassName}" />
	<property name="jdbcUrl" value="${jdbc.url}" />
	<property name="username" value="${jdbc.username}" />
	<property name="password" value="${jdbc.password}" />
	<property name="idleConnectionTestPeriod" value="0" />
	<property name="idleMaxAge" value="240" />
	<property name="maxConnectionsPerPartition" value="4" />
	<property name="minConnectionsPerPartition" value="2" />
	<property name="partitionCount" value="1" />
	<property name="acquireIncrement" value="5" />
	<property name="statementsCacheSize" value="100" />
	<property name="releaseHelperThreads" value="3" />
</bean>

2.配置Mybatis:
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
	<property name="dataSource" ref="dataSource" />
</bean>

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
	<property name="basePackage"
		value="mybatis的Mapper的xml和Mapper包空间" />
</bean>

3.配置Mybatis:
<tx:advice id="txAdvice" transaction-manager="transactionManager">
	<tx:attributes>
		<tx:method name="delete*" propagation="REQUIRED" read-only="false"
			rollback-for="java.lang.Exception" no-rollback-for="java.lang.RuntimeException" />
		<tx:method name="insert*" propagation="REQUIRED" read-only="false"
			rollback-for="java.lang.Exception" no-rollback-for="java.lang.RuntimeException" />
		<tx:method name="update*" propagation="REQUIRED" read-only="false"
			rollback-for="java.lang.Exception" no-rollback-for="java.lang.RuntimeException" />
		<tx:method name="find*" propagation="SUPPORTS" />
	</tx:attributes>
</tx:advice>

<aop:config>
	<aop:pointcut id="pc" expression="execution(* *.*.*(..))" />
	<aop:advisor pointcut-ref="pc" advice-ref="txAdvice" />
</aop:config>

这里需要AspectJ的Jar包,比较恶心的是aspectj没有maven支持,所以可以把AspectJ相关的jar包拷贝到war包里的lib下。

你可能感兴趣的:(java,spring,maven)