事务及其他

--applicationContext.xml

<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="*" propagation="REQUIRED" rollback-for="Exception" />
	</tx:attributes>
</tx:advice>

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

<tx:annotation-driven transaction-manager="txManager" />

--JedisPoolUtils.java

package com.atguigu1014.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class JedisPoolUtils {

	public static JedisPoolConfig c = new JedisPoolConfig(); // 连接池配置
	public static JedisPool jedisPool = null; // 连接池

	static {
		// c.setBlockWhenExhausted(true); // 连接耗尽则阻塞
		c.setLifo(true); // 后进先出
		c.setMaxIdle(10); // 最大空闲连接数为10
		c.setMinIdle(0); // 最小空闲连接数为0
		c.setMaxTotal(100); // 最大连接数为100
		c.setMaxWaitMillis(-1); // 设置最大等待毫秒数:无限制
		c.setMinEvictableIdleTimeMillis(180); // 逐出连接的最小空闲时间:30分钟
		c.setTestOnBorrow(true); // 获取连接时是否检查连接的有效性:是
		c.setTestWhileIdle(true); // 空闲时是否检查连接的有效性:是

		jedisPool = new JedisPool(c, "192.168.222.11", 6379); // 初始化连接池
	}

	/**
	 * 获取Jedis连接
	 * 
	 * @return Jedis连接
	 */
	public static Jedis getJedis() {
		return jedisPool.getResource();
	}

}

--pom.xml

<!-- 1 spring容器事务  -->
<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-tx</artifactId>
	<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-aspects</artifactId>
	<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
	<groupId>org.aspectj</groupId>
	<artifactId>aspectjweaver</artifactId>
	<version>1.6.8</version>
</dependency>
<dependency>
	<groupId>aopalliance</groupId>
	<artifactId>aopalliance</artifactId>
	<version>1.0</version>
</dependency>

--其他的pom配置文件参照pom


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Diligently_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值