Commit 7922024d8b174d8c57b9edfd0a031e722f366208
1 parent
a476e3ab
#chore:升级版本为2.0.0
1、不再兼容1.x版本; 2、升级spring版本为2.0.5;
Showing
7 changed files
with
62 additions
and
92 deletions
pom.xml
| @@ -6,20 +6,20 @@ | @@ -6,20 +6,20 @@ | ||
| 6 | 6 | ||
| 7 | <groupId>com.irrigation</groupId> | 7 | <groupId>com.irrigation</groupId> |
| 8 | <artifactId>common-lib</artifactId> | 8 | <artifactId>common-lib</artifactId> |
| 9 | - <version>1.2.4</version> | 9 | + <version>2.0.0</version> |
| 10 | 10 | ||
| 11 | <properties> | 11 | <properties> |
| 12 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | 12 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
| 13 | <java.version>1.8</java.version> | 13 | <java.version>1.8</java.version> |
| 14 | - <spring-boot.version>1.5.10.RELEASE</spring-boot.version> | 14 | + <spring-boot.version>2.0.5.RELEASE</spring-boot.version> |
| 15 | <swagger.version>2.7.0</swagger.version> | 15 | <swagger.version>2.7.0</swagger.version> |
| 16 | <lombok.version>1.16.20</lombok.version> | 16 | <lombok.version>1.16.20</lombok.version> |
| 17 | <commons-codec.version>1.11</commons-codec.version> | 17 | <commons-codec.version>1.11</commons-codec.version> |
| 18 | <guava.vsersion>20.0</guava.vsersion> | 18 | <guava.vsersion>20.0</guava.vsersion> |
| 19 | <slf4j.version>1.7.24</slf4j.version> | 19 | <slf4j.version>1.7.24</slf4j.version> |
| 20 | <fastjson.version>1.2.49</fastjson.version> | 20 | <fastjson.version>1.2.49</fastjson.version> |
| 21 | - <spring-web.version>4.3.14.RELEASE</spring-web.version> | ||
| 22 | - <spring-security-core.version>4.2.4.RELEASE</spring-security-core.version> | 21 | + <spring-web.version>5.0.9.RELEASE</spring-web.version> |
| 22 | + <spring-security-core.version>5.0.9.RELEASE</spring-security-core.version> | ||
| 23 | <ehcache.version>2.6.11</ehcache.version> | 23 | <ehcache.version>2.6.11</ehcache.version> |
| 24 | 24 | ||
| 25 | </properties> | 25 | </properties> |
src/main/java/com/irrigation/icl/cache/LayeringCacheAutoFactory.java
| @@ -9,6 +9,8 @@ import org.springframework.cache.CacheManager; | @@ -9,6 +9,8 @@ import org.springframework.cache.CacheManager; | ||
| 9 | import org.springframework.context.annotation.Bean; | 9 | import org.springframework.context.annotation.Bean; |
| 10 | import org.springframework.context.annotation.Conditional; | 10 | import org.springframework.context.annotation.Conditional; |
| 11 | import org.springframework.context.annotation.Configuration; | 11 | import org.springframework.context.annotation.Configuration; |
| 12 | +import org.springframework.data.redis.cache.RedisCacheConfiguration; | ||
| 13 | +import org.springframework.data.redis.cache.RedisCacheWriter; | ||
| 12 | import org.springframework.data.redis.connection.Message; | 14 | import org.springframework.data.redis.connection.Message; |
| 13 | import org.springframework.data.redis.connection.MessageListener; | 15 | import org.springframework.data.redis.connection.MessageListener; |
| 14 | import org.springframework.data.redis.connection.RedisConnectionFactory; | 16 | import org.springframework.data.redis.connection.RedisConnectionFactory; |
| @@ -17,6 +19,8 @@ import org.springframework.data.redis.listener.PatternTopic; | @@ -17,6 +19,8 @@ import org.springframework.data.redis.listener.PatternTopic; | ||
| 17 | import org.springframework.data.redis.listener.RedisMessageListenerContainer; | 19 | import org.springframework.data.redis.listener.RedisMessageListenerContainer; |
| 18 | import org.springframework.data.redis.listener.adapter.MessageListenerAdapter; | 20 | import org.springframework.data.redis.listener.adapter.MessageListenerAdapter; |
| 19 | 21 | ||
| 22 | +import java.time.Duration; | ||
| 23 | + | ||
| 20 | /** | 24 | /** |
| 21 | * @Author: boni | 25 | * @Author: boni |
| 22 | * @Date: 2018/8/24-下午2:37 | 26 | * @Date: 2018/8/24-下午2:37 |
| @@ -29,11 +33,19 @@ public class LayeringCacheAutoFactory { | @@ -29,11 +33,19 @@ public class LayeringCacheAutoFactory { | ||
| 29 | @Bean | 33 | @Bean |
| 30 | public LayeringCacheManager cacheManager(RedisTemplate<Object, Object> redisTemplate, | 34 | public LayeringCacheManager cacheManager(RedisTemplate<Object, Object> redisTemplate, |
| 31 | LayeringCacheProperties layeringCacheProperties) { | 35 | LayeringCacheProperties layeringCacheProperties) { |
| 32 | - LayeringCacheManager cacheManager = new LayeringCacheManager(redisTemplate, layeringCacheProperties); | ||
| 33 | - cacheManager.setUsePrefix(true); | 36 | + |
| 37 | + RedisCacheWriter redisCacheWriter = RedisCacheWriter | ||
| 38 | + .nonLockingRedisCacheWriter(redisTemplate.getConnectionFactory()); | ||
| 34 | long expire = layeringCacheProperties.getExpire() > 0L ? layeringCacheProperties.getExpire() : 120L; | 39 | long expire = layeringCacheProperties.getExpire() > 0L ? layeringCacheProperties.getExpire() : 120L; |
| 35 | - cacheManager.setExpires(layeringCacheProperties.getExpires()); | ||
| 36 | - cacheManager.setDefaultExpiration(expire); | 40 | + RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration |
| 41 | + .defaultCacheConfig() | ||
| 42 | + .entryTtl(Duration.ofSeconds(expire)); | ||
| 43 | + LayeringCacheManager cacheManager = | ||
| 44 | + new LayeringCacheManager( | ||
| 45 | + redisTemplate, | ||
| 46 | + redisCacheWriter, | ||
| 47 | + redisCacheConfiguration, | ||
| 48 | + layeringCacheProperties); | ||
| 37 | return cacheManager; | 49 | return cacheManager; |
| 38 | } | 50 | } |
| 39 | 51 |
src/main/java/com/irrigation/icl/cache/core/LayeringCache.java
| @@ -14,7 +14,8 @@ import net.sf.ehcache.store.MemoryStoreEvictionPolicy; | @@ -14,7 +14,8 @@ import net.sf.ehcache.store.MemoryStoreEvictionPolicy; | ||
| 14 | import org.springframework.cache.Cache; | 14 | import org.springframework.cache.Cache; |
| 15 | import org.springframework.cache.support.SimpleValueWrapper; | 15 | import org.springframework.cache.support.SimpleValueWrapper; |
| 16 | import org.springframework.data.redis.cache.RedisCache; | 16 | import org.springframework.data.redis.cache.RedisCache; |
| 17 | -import org.springframework.data.redis.core.RedisOperations; | 17 | +import org.springframework.data.redis.cache.RedisCacheConfiguration; |
| 18 | +import org.springframework.data.redis.cache.RedisCacheWriter; | ||
| 18 | import org.springframework.util.StopWatch; | 19 | import org.springframework.util.StopWatch; |
| 19 | 20 | ||
| 20 | import java.text.SimpleDateFormat; | 21 | import java.text.SimpleDateFormat; |
| @@ -36,17 +37,14 @@ public class LayeringCache extends RedisCache { | @@ -36,17 +37,14 @@ public class LayeringCache extends RedisCache { | ||
| 36 | private CacheManager layeringL1CacheManager; | 37 | private CacheManager layeringL1CacheManager; |
| 37 | private boolean layerL1Enable; | 38 | private boolean layerL1Enable; |
| 38 | private String ID; | 39 | private String ID; |
| 39 | -// private String HOST; | ||
| 40 | -// private String CACHE_STORE; | ||
| 41 | -// private String CACHE_STORE_SYNC; | ||
| 42 | 40 | ||
| 43 | - | ||
| 44 | - public LayeringCache(LayeringCacheManager layeringCacheManager, String name, byte[] prefix, | ||
| 45 | - RedisOperations<? extends Object, ? extends Object> redisOperations, long expiration) { | ||
| 46 | - super(name, prefix, redisOperations, expiration); | 41 | + public LayeringCache(LayeringCacheManager layeringCacheManager, String name, RedisCacheWriter cacheWriter, RedisCacheConfiguration cacheConfig) { |
| 42 | + super(name, cacheWriter, cacheConfig); | ||
| 47 | this.layeringCacheManager = layeringCacheManager; | 43 | this.layeringCacheManager = layeringCacheManager; |
| 44 | + | ||
| 48 | this.layeringCacheProperties = layeringCacheManager.getLayeringCacheProperties(); | 45 | this.layeringCacheProperties = layeringCacheManager.getLayeringCacheProperties(); |
| 49 | this.layerL1Enable = layeringCacheProperties.getCacheL1().isEnable(); | 46 | this.layerL1Enable = layeringCacheProperties.getCacheL1().isEnable(); |
| 47 | + | ||
| 50 | initEhcache(); | 48 | initEhcache(); |
| 51 | } | 49 | } |
| 52 | 50 | ||
| @@ -54,6 +52,7 @@ public class LayeringCache extends RedisCache { | @@ -54,6 +52,7 @@ public class LayeringCache extends RedisCache { | ||
| 54 | public Cache.ValueWrapper get(Object key) { | 52 | public Cache.ValueWrapper get(Object key) { |
| 55 | StopWatch stopWatch = new StopWatch(); | 53 | StopWatch stopWatch = new StopWatch(); |
| 56 | stopWatch.start(); | 54 | stopWatch.start(); |
| 55 | + | ||
| 57 | Ehcache ehCache = null; | 56 | Ehcache ehCache = null; |
| 58 | if (layerL1Enable) { | 57 | if (layerL1Enable) { |
| 59 | ehCache = getL1Cache(super.getName()); | 58 | ehCache = getL1Cache(super.getName()); |
| @@ -157,7 +156,7 @@ public class LayeringCache extends RedisCache { | @@ -157,7 +156,7 @@ public class LayeringCache extends RedisCache { | ||
| 157 | Callable<Ehcache> callable = () -> { | 156 | Callable<Ehcache> callable = () -> { |
| 158 | Ehcache cache = layeringL1CacheManager.getCache(name); | 157 | Ehcache cache = layeringL1CacheManager.getCache(name); |
| 159 | if (cache == null) { | 158 | if (cache == null) { |
| 160 | - CacheConfiguration cacheConfiguration = getCacheConfiguration(); | 159 | + CacheConfiguration cacheConfiguration = getEncacheCacheConfiguration(); |
| 161 | cacheConfiguration.setName(name); | 160 | cacheConfiguration.setName(name); |
| 162 | Ehcache ehcache = new net.sf.ehcache.Cache(cacheConfiguration); | 161 | Ehcache ehcache = new net.sf.ehcache.Cache(cacheConfiguration); |
| 163 | layeringL1CacheManager.addCache(ehcache); | 162 | layeringL1CacheManager.addCache(ehcache); |
| @@ -188,7 +187,7 @@ public class LayeringCache extends RedisCache { | @@ -188,7 +187,7 @@ public class LayeringCache extends RedisCache { | ||
| 188 | return simpleDateFormat.format(new Date()); | 187 | return simpleDateFormat.format(new Date()); |
| 189 | } | 188 | } |
| 190 | 189 | ||
| 191 | - private CacheConfiguration getCacheConfiguration() { | 190 | + private CacheConfiguration getEncacheCacheConfiguration() { |
| 192 | // Cache | 191 | // Cache |
| 193 | CacheConfiguration cacheConfiguration = new CacheConfiguration(); | 192 | CacheConfiguration cacheConfiguration = new CacheConfiguration(); |
| 194 | cacheConfiguration.setEternal(false); | 193 | cacheConfiguration.setEternal(false); |
| @@ -205,12 +204,6 @@ public class LayeringCache extends RedisCache { | @@ -205,12 +204,6 @@ public class LayeringCache extends RedisCache { | ||
| 205 | cacheConfiguration.copyOnRead(true); | 204 | cacheConfiguration.copyOnRead(true); |
| 206 | cacheConfiguration.copyOnWrite(true); | 205 | cacheConfiguration.copyOnWrite(true); |
| 207 | 206 | ||
| 208 | -// CopyStrategyConfiguration copyStrategyConfiguration = new CopyStrategyConfiguration(); | ||
| 209 | -// copyStrategyConfiguration.setClass(MyCopyStrategy.class.getName()); | ||
| 210 | -// copyStrategyConfiguration.setCopyStrategyInstance(new MyCopyStrategy()); | ||
| 211 | - | ||
| 212 | -// cacheConfiguration.addCopyStrategy(copyStrategyConfiguration); | ||
| 213 | - | ||
| 214 | cacheConfiguration.setTimeToIdleSeconds(layeringCacheProperties.getCacheL1().getLocalTimeToIdleSeconds()); | 207 | cacheConfiguration.setTimeToIdleSeconds(layeringCacheProperties.getCacheL1().getLocalTimeToIdleSeconds()); |
| 215 | cacheConfiguration.setTimeToLiveSeconds(layeringCacheProperties.getCacheL1().getLocalTimeToLiveSeconds()); | 208 | cacheConfiguration.setTimeToLiveSeconds(layeringCacheProperties.getCacheL1().getLocalTimeToLiveSeconds()); |
| 216 | 209 | ||
| @@ -220,13 +213,6 @@ public class LayeringCache extends RedisCache { | @@ -220,13 +213,6 @@ public class LayeringCache extends RedisCache { | ||
| 220 | private void initEhcache() { | 213 | private void initEhcache() { |
| 221 | if (layerL1Enable) { | 214 | if (layerL1Enable) { |
| 222 | this.ID = layeringCacheProperties.getCacheL1().getKey() + "." + getDate(); | 215 | this.ID = layeringCacheProperties.getCacheL1().getKey() + "." + getDate(); |
| 223 | -// this.HOST = Utils.getLocalHostIP(); | ||
| 224 | -// this.CACHE_STORE = layeringCacheProperties.getCacheL1().getKey() | ||
| 225 | -// + layeringCacheProperties.getCacheL1().getSeparator() | ||
| 226 | -// + "cache" | ||
| 227 | -// + layeringCacheProperties.getCacheL1().getSeparator() | ||
| 228 | -// + "store"; | ||
| 229 | -// this.CACHE_STORE_SYNC = this.CACHE_STORE + layeringCacheProperties.getCacheL1().getSeparator() + "sync"; | ||
| 230 | 216 | ||
| 231 | Configuration configuration = new Configuration(); | 217 | Configuration configuration = new Configuration(); |
| 232 | configuration.setName(this.ID); | 218 | configuration.setName(this.ID); |
| @@ -238,7 +224,7 @@ public class LayeringCache extends RedisCache { | @@ -238,7 +224,7 @@ public class LayeringCache extends RedisCache { | ||
| 238 | dsc.setPath(layeringCacheProperties.getCacheL1().getLocalStoreLocation() + this.ID); | 224 | dsc.setPath(layeringCacheProperties.getCacheL1().getLocalStoreLocation() + this.ID); |
| 239 | configuration.diskStore(dsc); | 225 | configuration.diskStore(dsc); |
| 240 | 226 | ||
| 241 | - CacheConfiguration cacheConfiguration = getCacheConfiguration(); | 227 | + CacheConfiguration cacheConfiguration = getEncacheCacheConfiguration(); |
| 242 | 228 | ||
| 243 | configuration.setDefaultCacheConfiguration(cacheConfiguration); | 229 | configuration.setDefaultCacheConfiguration(cacheConfiguration); |
| 244 | configuration.setDynamicConfig(false); | 230 | configuration.setDynamicConfig(false); |
| @@ -248,25 +234,4 @@ public class LayeringCache extends RedisCache { | @@ -248,25 +234,4 @@ public class LayeringCache extends RedisCache { | ||
| 248 | layeringL1CacheManager = new CacheManager(configuration); | 234 | layeringL1CacheManager = new CacheManager(configuration); |
| 249 | } | 235 | } |
| 250 | } | 236 | } |
| 251 | -// | ||
| 252 | -// class MyCopyStrategy implements ReadWriteCopyStrategy<Element> { | ||
| 253 | -// @Override | ||
| 254 | -// public Element copyForWrite(Element value) { | ||
| 255 | -// if (value != null) { | ||
| 256 | -// Object temp = (Serializable) value.getObjectValue(); | ||
| 257 | -// return new Element(value.getObjectKey(), temp); | ||
| 258 | -// } | ||
| 259 | -// return value; | ||
| 260 | -// } | ||
| 261 | -// | ||
| 262 | -// @Override | ||
| 263 | -// public Element copyForRead(Element storedValue) { | ||
| 264 | -// if (storedValue != null) { | ||
| 265 | -// Object temp = (Serializable) storedValue.getObjectValue(); | ||
| 266 | -// return new Element(storedValue.getObjectKey(), temp); | ||
| 267 | -// } | ||
| 268 | -// return storedValue; | ||
| 269 | -// | ||
| 270 | -// } | ||
| 271 | -// } | ||
| 272 | } | 237 | } |
src/main/java/com/irrigation/icl/cache/core/LayeringCacheLoadCondition.java
| 1 | package com.irrigation.icl.cache.core; | 1 | package com.irrigation.icl.cache.core; |
| 2 | 2 | ||
| 3 | -import org.springframework.boot.bind.RelaxedPropertyResolver; | 3 | +import org.springframework.boot.context.properties.bind.Binder; |
| 4 | import org.springframework.context.annotation.Condition; | 4 | import org.springframework.context.annotation.Condition; |
| 5 | import org.springframework.context.annotation.ConditionContext; | 5 | import org.springframework.context.annotation.ConditionContext; |
| 6 | import org.springframework.core.type.AnnotatedTypeMetadata; | 6 | import org.springframework.core.type.AnnotatedTypeMetadata; |
| @@ -12,13 +12,10 @@ import org.springframework.core.type.AnnotatedTypeMetadata; | @@ -12,13 +12,10 @@ import org.springframework.core.type.AnnotatedTypeMetadata; | ||
| 12 | public class LayeringCacheLoadCondition implements Condition { | 12 | public class LayeringCacheLoadCondition implements Condition { |
| 13 | @Override | 13 | @Override |
| 14 | public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { | 14 | public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { |
| 15 | - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( | ||
| 16 | - context.getEnvironment(), "springext.cache."); | ||
| 17 | - | ||
| 18 | - Boolean enable = resolver.getProperty("enable",Boolean.class); | ||
| 19 | - if(enable == null){ | ||
| 20 | - return false; | ||
| 21 | - } | 15 | + Boolean enable = Binder |
| 16 | + .get(context.getEnvironment()) | ||
| 17 | + .bind("springext.cache.enable", Boolean.class) | ||
| 18 | + .orElse(false); | ||
| 22 | return enable.booleanValue(); | 19 | return enable.booleanValue(); |
| 23 | 20 | ||
| 24 | } | 21 | } |
src/main/java/com/irrigation/icl/cache/core/LayeringCacheManager.java
| 1 | package com.irrigation.icl.cache.core; | 1 | package com.irrigation.icl.cache.core; |
| 2 | 2 | ||
| 3 | import com.irrigation.icl.cache.Command; | 3 | import com.irrigation.icl.cache.Command; |
| 4 | +import lombok.Getter; | ||
| 4 | import org.springframework.data.redis.cache.RedisCache; | 5 | import org.springframework.data.redis.cache.RedisCache; |
| 6 | +import org.springframework.data.redis.cache.RedisCacheConfiguration; | ||
| 5 | import org.springframework.data.redis.cache.RedisCacheManager; | 7 | import org.springframework.data.redis.cache.RedisCacheManager; |
| 6 | -import org.springframework.data.redis.core.RedisOperations; | 8 | +import org.springframework.data.redis.cache.RedisCacheWriter; |
| 9 | +import org.springframework.data.redis.core.RedisTemplate; | ||
| 7 | 10 | ||
| 8 | /** | 11 | /** |
| 9 | * @Author: boni | 12 | * @Author: boni |
| 10 | * @Date: 2018/8/24-下午2:29 | 13 | * @Date: 2018/8/24-下午2:29 |
| 11 | */ | 14 | */ |
| 15 | +@Getter | ||
| 12 | public class LayeringCacheManager extends RedisCacheManager { | 16 | public class LayeringCacheManager extends RedisCacheManager { |
| 13 | 17 | ||
| 18 | + final RedisCacheWriter cacheWriter; | ||
| 19 | + final RedisCacheConfiguration redisCacheConfiguration; | ||
| 14 | private LayeringCacheProperties layeringCacheProperties; | 20 | private LayeringCacheProperties layeringCacheProperties; |
| 15 | - | ||
| 16 | - public LayeringCacheProperties getLayeringCacheProperties() { | ||
| 17 | - return layeringCacheProperties; | ||
| 18 | - } | ||
| 19 | - | ||
| 20 | - public void setLayeringCacheProperties(LayeringCacheProperties layeringCacheProperties) { | 21 | + private RedisTemplate redisTemplate; |
| 22 | + | ||
| 23 | + public LayeringCacheManager(RedisTemplate redisTemplate, RedisCacheWriter cacheWriter, RedisCacheConfiguration redisCacheConfiguration, | ||
| 24 | + LayeringCacheProperties layeringCacheProperties) { | ||
| 25 | + super(cacheWriter, redisCacheConfiguration); | ||
| 26 | + this.cacheWriter = cacheWriter; | ||
| 27 | + this.redisCacheConfiguration = redisCacheConfiguration; | ||
| 28 | + this.redisTemplate = redisTemplate; | ||
| 21 | this.layeringCacheProperties = layeringCacheProperties; | 29 | this.layeringCacheProperties = layeringCacheProperties; |
| 22 | } | 30 | } |
| 23 | 31 | ||
| 24 | - public LayeringCacheManager(RedisOperations redisOperations, LayeringCacheProperties layeringCacheProperties) { | ||
| 25 | - super(redisOperations); | ||
| 26 | - this.layeringCacheProperties = layeringCacheProperties; | ||
| 27 | - } | ||
| 28 | - | ||
| 29 | - @SuppressWarnings("unchecked") | ||
| 30 | @Override | 32 | @Override |
| 31 | - protected RedisCache createCache(String cacheName) { | ||
| 32 | - long expiration = computeExpiration(cacheName); | ||
| 33 | - return new LayeringCache( | ||
| 34 | - this, | ||
| 35 | - cacheName, | ||
| 36 | - (this.isUsePrefix() ? this.getCachePrefix().prefix(cacheName) : null), | ||
| 37 | - this.getRedisOperations(), | ||
| 38 | - expiration); | 33 | + protected RedisCache getMissingCache(String name) { |
| 34 | + return new LayeringCache(this, name, this.cacheWriter, this.redisCacheConfiguration); | ||
| 39 | } | 35 | } |
| 40 | 36 | ||
| 41 | - | ||
| 42 | //notify other redis clent to update L1 | 37 | //notify other redis clent to update L1 |
| 43 | public void publishMessage(Command command) { | 38 | public void publishMessage(Command command) { |
| 44 | - this.getRedisOperations().convertAndSend(this.getLayeringCacheProperties().getCacheL1().getTopic(), command); | 39 | + this.getRedisTemplate().convertAndSend(this.getLayeringCacheProperties().getCacheL1().getTopic(), command); |
| 45 | } | 40 | } |
| 46 | 41 | ||
| 47 | 42 |
src/main/java/com/irrigation/icl/cache/core/LayeringCacheProperties.java
| @@ -73,10 +73,10 @@ public class LayeringCacheProperties { | @@ -73,10 +73,10 @@ public class LayeringCacheProperties { | ||
| 73 | /** | 73 | /** |
| 74 | * 本地缓存过期时间,单位秒,默认10分钟 | 74 | * 本地缓存过期时间,单位秒,默认10分钟 |
| 75 | */ | 75 | */ |
| 76 | - private int localTimeToLiveSeconds = 1 * 60; | ||
| 77 | - private int localTimeToIdleSeconds = 0; | 76 | + private int localTimeToLiveSeconds = 10 * 60; |
| 77 | + private int localTimeToIdleSeconds = 30; | ||
| 78 | /** | 78 | /** |
| 79 | - * 本地缓存清理周期,单位秒,默认3分钟 | 79 | + * 本地缓存清理周期,单位秒,默认90秒 |
| 80 | */ | 80 | */ |
| 81 | private int localDiskExpiryThreadIntervalSeconds = 90; | 81 | private int localDiskExpiryThreadIntervalSeconds = 90; |
| 82 | } | 82 | } |
src/main/java/com/irrigation/icl/utils/PasswordEncoderUtil.java
| 1 | package com.irrigation.icl.utils; | 1 | package com.irrigation.icl.utils; |
| 2 | 2 | ||
| 3 | -import org.springframework.security.authentication.encoding.BasePasswordEncoder; | ||
| 4 | -import org.springframework.security.authentication.encoding.Md5PasswordEncoder; | 3 | + |
| 4 | +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
| 5 | +import org.springframework.security.crypto.password.PasswordEncoder; | ||
| 5 | 6 | ||
| 6 | public class PasswordEncoderUtil { | 7 | public class PasswordEncoderUtil { |
| 7 | 8 | ||
| 8 | - private final static BasePasswordEncoder encoder = new Md5PasswordEncoder(); | 9 | + private final static PasswordEncoder encoder = new BCryptPasswordEncoder(4); |
| 9 | 10 | ||
| 10 | public static String encodePassword(String password) { | 11 | public static String encodePassword(String password) { |
| 11 | - return encoder.encodePassword(password, null); | 12 | + return encoder.encode(password); |
| 12 | } | 13 | } |
| 13 | 14 | ||
| 14 | public static boolean isPasswordValid(String rawPassword, String encodedPassword) { | 15 | public static boolean isPasswordValid(String rawPassword, String encodedPassword) { |
| 15 | - return encoder.isPasswordValid(encodedPassword, rawPassword, null); | 16 | + return encoder.matches(rawPassword, encodedPassword); |
| 16 | } | 17 | } |
| 17 | 18 | ||
| 18 | } | 19 | } |