解决警告

This commit is contained in:
D 2024-04-27 17:34:23 +08:00
parent 8c59c5002d
commit 51794335ba
4 changed files with 10 additions and 18 deletions

View File

@ -41,7 +41,6 @@ public class CacheUtils {
* @param cacheName * @param cacheName
* @return * @return
*/ */
@SuppressWarnings(value = { "unchecked", "rawtypes" })
public static Set<String> getkeys(String cacheName) { public static Set<String> getkeys(String cacheName) {
Cache cache = getCacheManager().getCache(cacheName); Cache cache = getCacheManager().getCache(cacheName);
CacheKeys cacheGetKets = SpringUtils.getBean(CacheKeys.class); CacheKeys cacheGetKets = SpringUtils.getBean(CacheKeys.class);

View File

@ -9,6 +9,7 @@ import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONReader; import com.alibaba.fastjson2.JSONReader;
import com.alibaba.fastjson2.JSONWriter; import com.alibaba.fastjson2.JSONWriter;
// import com.alibaba.fastjson2.filter.Filter; // import com.alibaba.fastjson2.filter.Filter;
import com.alibaba.fastjson2.filter.Filter;
/** /**
* Redis使用FastJson序列化 * Redis使用FastJson序列化
@ -19,10 +20,10 @@ public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T>
{ {
public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
// static final Filter autoTypeFilter = JSONReader.autoTypeFilter( static final Filter autoTypeFilter = JSONReader.autoTypeFilter(
// 按需加上需要支持自动类型的类名前缀范围越小越安全 "org.springframework.security.core.authority.SimpleGrantedAuthority",
// "org.springframework.security.core.authority.SimpleGrantedAuthority" "com.ruoyi.***"
// ); );
private Class<T> clazz; private Class<T> clazz;
@ -50,9 +51,6 @@ public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T>
return null; return null;
} }
String str = new String(bytes, DEFAULT_CHARSET); String str = new String(bytes, DEFAULT_CHARSET);
return JSON.parseObject(str, clazz, autoTypeFilter);
// TODO 自动类型官方说不安全所以弃用了代替方案是autoTypeFilter,在注释中给了案例
return JSON.parseObject(str, clazz, JSONReader.Feature.SupportAutoType);
// return JSON.parseObject(str, clazz, autoTypeFilter);
} }
} }

View File

@ -3,24 +3,27 @@ package com.ruoyi.ehcache.config;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.ehcache.core.EhcacheBase; import org.ehcache.core.EhcacheBase;
import org.ehcache.impl.internal.concurrent.ConcurrentHashMap;
import org.ehcache.impl.internal.store.heap.OnHeapStore; import org.ehcache.impl.internal.store.heap.OnHeapStore;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache; import org.springframework.cache.Cache;
import org.springframework.cache.jcache.JCacheCache; import org.springframework.cache.jcache.JCacheCache;
import org.springframework.cache.jcache.JCacheCacheManager; import org.springframework.cache.jcache.JCacheCacheManager;
import org.springframework.stereotype.Component;
import com.ruoyi.common.interceptor.cache.CacheKeys; import com.ruoyi.common.interceptor.cache.CacheKeys;
import com.ruoyi.common.interceptor.cache.CacheNoTimeOut; import com.ruoyi.common.interceptor.cache.CacheNoTimeOut;
@Component
public class Ehcache3Cache implements CacheNoTimeOut, CacheKeys { public class Ehcache3Cache implements CacheNoTimeOut, CacheKeys {
@Autowired @Autowired
private JCacheCacheManager jCacheCacheManager; private JCacheCacheManager jCacheCacheManager;
@Override @Override
@SuppressWarnings(value = { "unchecked", "rawtypes" })
public Set<String> getCachekeys(Cache cache) { public Set<String> getCachekeys(Cache cache) {
Set<String> keyset = new HashSet<>(); Set<String> keyset = new HashSet<>();
try { try {

View File

@ -1,8 +1,5 @@
package com.ruoyi.ehcache.config; package com.ruoyi.ehcache.config;
import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.cache.CacheManager; import javax.cache.CacheManager;
@ -11,14 +8,9 @@ import javax.cache.configuration.MutableConfiguration;
import javax.cache.expiry.CreatedExpiryPolicy; import javax.cache.expiry.CreatedExpiryPolicy;
import javax.cache.expiry.Duration; import javax.cache.expiry.Duration;
import org.ehcache.core.EhcacheBase;
import org.ehcache.impl.internal.concurrent.ConcurrentHashMap;
import org.ehcache.impl.internal.store.heap.OnHeapStore;
import org.ehcache.jsr107.EhcacheCachingProvider; import org.ehcache.jsr107.EhcacheCachingProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cache.Cache;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.jcache.JCacheCache;
import org.springframework.cache.jcache.JCacheCacheManager; import org.springframework.cache.jcache.JCacheCacheManager;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;