--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
| |
| <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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)