事务及其他

--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


posted @   diligently  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示