Commit a070d12bed2e38b680758e3541cf144300889c2e
1 parent
41e3ed79
#fix:修复不开启1级缓存时报NullException的bug
Showing
3 changed files
with
10 additions
and
5 deletions
pom.xml
src/main/java/com/irrigation/icl/cache/LayeringCacheAutoFactory.java
| ... | ... | @@ -55,8 +55,10 @@ public class LayeringCacheAutoFactory { |
| 55 | 55 | MessageListenerAdapter listenerAdapter) { |
| 56 | 56 | RedisMessageListenerContainer container = new RedisMessageListenerContainer(); |
| 57 | 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 | 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 | 20 | |
| 21 | 21 | import java.text.SimpleDateFormat; |
| 22 | 22 | import java.util.Date; |
| 23 | +import java.util.Optional; | |
| 23 | 24 | import java.util.concurrent.Callable; |
| 24 | 25 | import java.util.concurrent.ConcurrentHashMap; |
| 25 | 26 | import java.util.concurrent.Future; |
| ... | ... | @@ -41,9 +42,11 @@ public class LayeringCache extends RedisCache { |
| 41 | 42 | public LayeringCache(LayeringCacheManager layeringCacheManager, String name, RedisCacheWriter cacheWriter, RedisCacheConfiguration cacheConfig) { |
| 42 | 43 | super(name, cacheWriter, cacheConfig); |
| 43 | 44 | this.layeringCacheManager = layeringCacheManager; |
| 44 | - | |
| 45 | 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 | 51 | initEhcache(); |
| 49 | 52 | } | ... | ... |