mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-19 20:15:46 +00:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
8cc4eaf64d
2 files changed
+13
-5
No files matched your search
@@ -40,6 +40,7 @@ import org.bson.codecs.configuration.CodecRegistries;
|
|||||||
import org.bson.codecs.configuration.CodecRegistry;
|
import org.bson.codecs.configuration.CodecRegistry;
|
||||||
import org.bson.codecs.pojo.PojoCodecProvider;
|
import org.bson.codecs.pojo.PojoCodecProvider;
|
||||||
import org.bson.types.ObjectId;
|
import org.bson.types.ObjectId;
|
||||||
|
import org.springframework.aop.framework.AopProxyUtils;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||||
import org.springframework.core.type.AnnotationMetadata;
|
import org.springframework.core.type.AnnotationMetadata;
|
||||||
@@ -191,7 +192,9 @@ public class OrmManager implements IOrmManager {
|
|||||||
var applicationContext = OrmContext.getApplicationContext();
|
var applicationContext = OrmContext.getApplicationContext();
|
||||||
var componentBeans = applicationContext.getBeansWithAnnotation(Component.class);
|
var componentBeans = applicationContext.getBeansWithAnnotation(Component.class);
|
||||||
for (var bean : componentBeans.values()) {
|
for (var bean : componentBeans.values()) {
|
||||||
ReflectionUtils.filterFieldsInClass(bean.getClass()
|
//防止被CGLIB代理时 直接赋值无效
|
||||||
|
var targetBean = Objects.requireNonNullElse(AopProxyUtils.getSingletonTarget(bean), bean);
|
||||||
|
ReflectionUtils.filterFieldsInClass(targetBean.getClass()
|
||||||
, field -> field.isAnnotationPresent(EntityCacheAutowired.class)
|
, field -> field.isAnnotationPresent(EntityCacheAutowired.class)
|
||||||
, field -> {
|
, field -> {
|
||||||
Type type = field.getGenericType();
|
Type type = field.getGenericType();
|
||||||
@@ -212,7 +215,7 @@ public class OrmManager implements IOrmManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReflectionUtils.makeAccessible(field);
|
ReflectionUtils.makeAccessible(field);
|
||||||
ReflectionUtils.setField(field, bean, entityCaches);
|
ReflectionUtils.setField(field, targetBean, entityCaches);
|
||||||
allEntityCachesUsableMap.put(entityClazz, true);
|
allEntityCachesUsableMap.put(entityClazz, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import com.zfoo.storage.model.StorageDefinition;
|
|||||||
import com.zfoo.storage.util.function.Func1;
|
import com.zfoo.storage.util.function.Func1;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.aop.framework.AopProxyUtils;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.core.io.DefaultResourceLoader;
|
import org.springframework.core.io.DefaultResourceLoader;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
@@ -148,12 +149,16 @@ public class StorageManager implements IStorageManager {
|
|||||||
var applicationContext = StorageContext.getApplicationContext();
|
var applicationContext = StorageContext.getApplicationContext();
|
||||||
var componentBeans = applicationContext.getBeansWithAnnotation(Component.class);
|
var componentBeans = applicationContext.getBeansWithAnnotation(Component.class);
|
||||||
for (var bean : componentBeans.values()) {
|
for (var bean : componentBeans.values()) {
|
||||||
var clazz = bean.getClass();
|
|
||||||
|
//防止被CGLIB代理时 直接赋值无效
|
||||||
|
var targetBean = Objects.requireNonNullElse(AopProxyUtils.getSingletonTarget(bean), bean);
|
||||||
|
|
||||||
|
var clazz = targetBean.getClass();
|
||||||
ReflectionUtils.filterFieldsInClass(clazz, field -> field.isAnnotationPresent(StorageAutowired.class), field -> {
|
ReflectionUtils.filterFieldsInClass(clazz, field -> field.isAnnotationPresent(StorageAutowired.class), field -> {
|
||||||
Type type = field.getGenericType();
|
Type type = field.getGenericType();
|
||||||
|
|
||||||
if (!(type instanceof ParameterizedType)) {
|
if (!(type instanceof ParameterizedType)) {
|
||||||
throw new RuntimeException(StringUtils.format("[bean:{}] type declaration is incorrect, not a generic class", bean.getClass().getSimpleName()));
|
throw new RuntimeException(StringUtils.format("[bean:{}] type declaration is incorrect, not a generic class", targetBean.getClass().getSimpleName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Type[] types = ((ParameterizedType) type).getActualTypeArguments();
|
Type[] types = ((ParameterizedType) type).getActualTypeArguments();
|
||||||
@@ -181,7 +186,7 @@ public class StorageManager implements IStorageManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReflectionUtils.makeAccessible(field);
|
ReflectionUtils.makeAccessible(field);
|
||||||
ReflectionUtils.setField(field, bean, storage);
|
ReflectionUtils.setField(field, targetBean, storage);
|
||||||
storage.setRecycle(false);
|
storage.setRecycle(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user