From 4884f2bc65c73ce5c25f8efee0d1f2a27663a57e Mon Sep 17 00:00:00 2001 From: zjh <1084500556@qq.com> Date: 星期二, 02 四月 2024 17:16:27 +0800 Subject: [PATCH] zjh 2024/04/02-1 --- ltkj-framework/src/main/java/com/ltkj/framework/config/RedisConfig.java | 72 ++++++++++++++++++++++++ ltkj-framework/pom.xml | 4 + ltkj-admin/src/main/resources/application.yml | 52 ++++++++-------- 3 files changed, 102 insertions(+), 26 deletions(-) diff --git a/ltkj-admin/src/main/resources/application.yml b/ltkj-admin/src/main/resources/application.yml index c8bd9de..45d1eb1 100644 --- a/ltkj-admin/src/main/resources/application.yml +++ b/ltkj-admin/src/main/resources/application.yml @@ -71,29 +71,29 @@ # 鐑儴缃插紑鍏� enabled: true # redis 閰嶇疆 - redis: - # 鍦板潃 - host: 101.42.27.146 -# host: localhost - # 绔彛锛岄粯璁や负6379 - port: 6379 - # 鏁版嵁搴撶储寮� - database: 0 - # 瀵嗙爜 - password: 654321 -# password: 123456 - # 杩炴帴瓒呮椂鏃堕棿 - timeout: 120s - lettuce: - pool: - # 杩炴帴姹犱腑鐨勬渶灏忕┖闂茶繛鎺� - min-idle: 0 - # 杩炴帴姹犱腑鐨勬渶澶х┖闂茶繛鎺� - max-idle: 8 - # 杩炴帴姹犵殑鏈�澶ф暟鎹簱杩炴帴鏁� - max-active: 8 - # #杩炴帴姹犳渶澶ч樆濉炵瓑寰呮椂闂达紙浣跨敤璐熷�艰〃绀烘病鏈夐檺鍒讹級 - max-wait: -1ms +# redis: +# # 鍦板潃 +# host: 101.42.27.146 +## host: localhost +# # 绔彛锛岄粯璁や负6379 +# port: 6379 +# # 鏁版嵁搴撶储寮� +# database: 0 +# # 瀵嗙爜 +# password: 654321 +## password: 123456 +# # 杩炴帴瓒呮椂鏃堕棿 +# timeout: 120s +# lettuce: +# pool: +# # 杩炴帴姹犱腑鐨勬渶灏忕┖闂茶繛鎺� +# min-idle: 0 +# # 杩炴帴姹犱腑鐨勬渶澶х┖闂茶繛鎺� +# max-idle: 8 +# # 杩炴帴姹犵殑鏈�澶ф暟鎹簱杩炴帴鏁� +# max-active: 8 +# # #杩炴帴姹犳渶澶ч樆濉炵瓑寰呮椂闂达紙浣跨敤璐熷�艰〃绀烘病鏈夐檺鍒讹級 +# max-wait: -1ms # 閭欢 mail: # from 瑕佸拰 username 涓�鑷�, 鍚﹀垯鎶ラ敊 @@ -215,12 +215,12 @@ #绉湪鎶ヨ〃璁块棶鍦板潃 jimu: -# path: https://ltpeis.xaltjdkj.cn:5011/ltkj-admin - path: https://ltpeis.xaltjdkj.cn:5021/ltkj-admin + path: https://ltpeis.xaltjdkj.cn:5011/ltkj-admin +# path: https://ltpeis.xaltjdkj.cn:5021/ltkj-admin # path: http://192.168.0.5:5000/ltkj-admin # path: http://10.168.0.9:5011 # path: http://192.168.0.105:5011 -# path: http://192.168.0.99:8081/ltkj-admin +# path: http://192.168.0.112:5011 jeecg : diff --git a/ltkj-framework/pom.xml b/ltkj-framework/pom.xml index 17e8210..3eb198b 100644 --- a/ltkj-framework/pom.xml +++ b/ltkj-framework/pom.xml @@ -16,6 +16,10 @@ </description> <dependencies> + <dependency> + <groupId>redis.clients</groupId> + <artifactId>jedis</artifactId> + </dependency> <!-- SpringBoot Web瀹瑰櫒 --> <dependency> diff --git a/ltkj-framework/src/main/java/com/ltkj/framework/config/RedisConfig.java b/ltkj-framework/src/main/java/com/ltkj/framework/config/RedisConfig.java index 42ca229..393c1c5 100644 --- a/ltkj-framework/src/main/java/com/ltkj/framework/config/RedisConfig.java +++ b/ltkj-framework/src/main/java/com/ltkj/framework/config/RedisConfig.java @@ -1,13 +1,19 @@ package com.ltkj.framework.config; +import lombok.extern.slf4j.Slf4j; import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.script.DefaultRedisScript; import org.springframework.data.redis.serializer.StringRedisSerializer; +import redis.clients.jedis.JedisPoolConfig; + +import java.io.*; +import java.util.Properties; /** * redis閰嶇疆 @@ -16,8 +22,74 @@ */ @Configuration @EnableCaching +@Slf4j public class RedisConfig extends CachingConfigurerSupport { @Bean + public JedisPoolConfig jedisPoolConfig() { + JedisPoolConfig config = new JedisPoolConfig(); + // 璁剧疆JedisPoolConfig鐨勭浉鍏冲弬鏁帮紝渚嬪鏈�澶ц繛鎺ユ暟銆佹渶澶х┖闂叉椂闂寸瓑 +// config.setMaxIdle(8); +// config.setMaxIdle(0); +// config.setMaxTotal(8); +// config.setTimeBetweenEvictionRunsMillis(10); + return config; + } + @Bean + public RedisConnectionFactory redisConnectionFactory(JedisPoolConfig jedisPoolConfig) { + JedisConnectionFactory factory = new JedisConnectionFactory(); + // 浠庢枃浠朵腑璇诲彇閰嶇疆淇℃伅 + try { + FileInputStream fis = null; + Properties props = new Properties(); + try { + fis = new FileInputStream("D:\\ltkjprojectconf\\config.properties"); + } catch (FileNotFoundException e) { + log.info("閰嶇疆鏂囦欢鎵句笉鍒� 绯荤粺姝e湪鍒涘缓锛�"); + File f = new File("D:\\ltkjprojectconf"); + if(!f.exists()){ + f.mkdirs(); + } + File file = new File("D:\\ltkjprojectconf\\config.properties"); + try { + FileWriter fileWriter = new FileWriter(file); + fileWriter.write("ip = 浣犵殑涓绘暟鎹簱杩炴帴ip鍦板潃\n"); + fileWriter.write("prot = 浣犵殑涓绘暟鎹簱杩炴帴绔彛\n"); + fileWriter.write("name = 浣犵殑涓绘暟鎹簱杩炴帴鍚嶇О\n"); + fileWriter.write("username = 浣犵殑涓绘暟鎹簱杩炴帴鐢ㄦ埛鍚峔n"); + fileWriter.write("password = 浣犵殑涓绘暟鎹簱杩炴帴瀵嗙爜\n"); + fileWriter.write("redisIp = 浣犵殑redisIp鍦板潃"); + fileWriter.write("redisProt = 浣犵殑redis绔彛"); + fileWriter.write("redisPassword = 浣犵殑redis瀵嗙爜"); + fileWriter.write(""); + fileWriter.close(); + log.info("閰嶇疆鏂囦欢鍒涘缓鎴愬姛锛�"); + } catch (IOException ioException) { + log.info("閰嶇疆鏂囦欢鍒涘缓澶辫触 璇疯仈绯荤鐞嗗憳鎵嬪姩鍒涘缓锛�"); + ioException.printStackTrace(); + } + e.printStackTrace(); + } + props.load(fis); + fis.close(); + // 鑾峰彇灞炴�у�煎苟璧嬪�� + factory.setPoolConfig(jedisPoolConfig); + // 璁剧疆Redis鏈嶅姟鍣ㄧ殑鍦板潃鍜岀鍙e彿 + factory.setHostName(props.getProperty("redisIp")); + factory.setPort(Integer.parseInt(props.getProperty("redisProt"))); + // 濡傛灉闇�瑕佸瘑鐮侀獙璇侊紝璁剧疆瀵嗙爜 + factory.setPassword(props.getProperty("redisPassword")); + // 璁剧疆鍏朵粬鍙傛暟锛屽鏁版嵁搴撶储寮曠瓑 + factory.setDatabase(0); + // 鏈�鍚庯紝鍒濆鍖栬繛鎺� + factory.afterPropertiesSet(); + log.info("redis杩炴帴鎴愬姛!!!"); + } catch (IOException e) { + log.info("redis杩炴帴澶辫触 璇疯仈绯荤鐞嗗憳锛�"); + e.printStackTrace(); + } + return factory; + } + @Bean @SuppressWarnings(value = {"unchecked", "rawtypes"}) public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) { RedisTemplate<Object, Object> template = new RedisTemplate<>(); -- Gitblit v1.8.0