Commit a070d12bed2e38b680758e3541cf144300889c2e
1 parent
41e3ed79
#fix:修复不开启1级缓存时报NullException的bug
Showing
3 changed files
with
10 additions
and
5 deletions
pom.xml
| @@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
| 6 | 6 | ||
| 7 | <groupId>com.irrigation</groupId> | 7 | <groupId>com.irrigation</groupId> |
| 8 | <artifactId>common-lib</artifactId> | 8 | <artifactId>common-lib</artifactId> |
| 9 | - <version>2.0.0</version> | 9 | + <version>2.0.1</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> |
src/main/java/com/irrigation/icl/cache/LayeringCacheAutoFactory.java
| @@ -55,8 +55,10 @@ public class LayeringCacheAutoFactory { | @@ -55,8 +55,10 @@ public class LayeringCacheAutoFactory { | ||
| 55 | MessageListenerAdapter listenerAdapter) { | 55 | MessageListenerAdapter listenerAdapter) { |
| 56 | RedisMessageListenerContainer container = new RedisMessageListenerContainer(); | 56 | RedisMessageListenerContainer container = new RedisMessageListenerContainer(); |
| 57 | container.setConnectionFactory(connectionFactory); | 57 | container.setConnectionFactory(connectionFactory); |
| 58 | - container.addMessageListener(listenerAdapter, new PatternTopic(layeringCacheProperties.getCacheL1().getTopic())); | ||
| 59 | - | 58 | + LayeringCacheProperties.L1 l1 = layeringCacheProperties.getCacheL1(); |
| 59 | + if (l1 != null) { | ||
| 60 | + container.addMessageListener(listenerAdapter, new PatternTopic(layeringCacheProperties.getCacheL1().getTopic())); | ||
| 61 | + } | ||
| 60 | return container; | 62 | return container; |
| 61 | } | 63 | } |
| 62 | 64 |
src/main/java/com/irrigation/icl/cache/core/LayeringCache.java
| @@ -20,6 +20,7 @@ import org.springframework.util.StopWatch; | @@ -20,6 +20,7 @@ import org.springframework.util.StopWatch; | ||
| 20 | 20 | ||
| 21 | import java.text.SimpleDateFormat; | 21 | import java.text.SimpleDateFormat; |
| 22 | import java.util.Date; | 22 | import java.util.Date; |
| 23 | +import java.util.Optional; | ||
| 23 | import java.util.concurrent.Callable; | 24 | import java.util.concurrent.Callable; |
| 24 | import java.util.concurrent.ConcurrentHashMap; | 25 | import java.util.concurrent.ConcurrentHashMap; |
| 25 | import java.util.concurrent.Future; | 26 | import java.util.concurrent.Future; |
| @@ -41,9 +42,11 @@ public class LayeringCache extends RedisCache { | @@ -41,9 +42,11 @@ public class LayeringCache extends RedisCache { | ||
| 41 | public LayeringCache(LayeringCacheManager layeringCacheManager, String name, RedisCacheWriter cacheWriter, RedisCacheConfiguration cacheConfig) { | 42 | public LayeringCache(LayeringCacheManager layeringCacheManager, String name, RedisCacheWriter cacheWriter, RedisCacheConfiguration cacheConfig) { |
| 42 | super(name, cacheWriter, cacheConfig); | 43 | super(name, cacheWriter, cacheConfig); |
| 43 | this.layeringCacheManager = layeringCacheManager; | 44 | this.layeringCacheManager = layeringCacheManager; |
| 44 | - | ||
| 45 | this.layeringCacheProperties = layeringCacheManager.getLayeringCacheProperties(); | 45 | this.layeringCacheProperties = layeringCacheManager.getLayeringCacheProperties(); |
| 46 | - this.layerL1Enable = layeringCacheProperties.getCacheL1().isEnable(); | 46 | + this.layerL1Enable = |
| 47 | + Optional.ofNullable(layeringCacheProperties.getCacheL1()) | ||
| 48 | + .orElse(new LayeringCacheProperties.L1()) | ||
| 49 | + .isEnable(); | ||
| 47 | 50 | ||
| 48 | initEhcache(); | 51 | initEhcache(); |
| 49 | } | 52 | } |