mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-21 08:27:11 +00:00
revert[proxy]: bean should be pojo class
This commit is contained in:
@@ -43,11 +43,15 @@ public class EventRegisterProcessor implements BeanPostProcessor {
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
var clazz = bean.getClass();
|
||||
var methods = ReflectionUtils.getMethodsByAnnotation(clazz, EventReceiver.class);
|
||||
var methods = ReflectionUtils.getMethodsByAnnoInPOJOClass(clazz, EventReceiver.class);
|
||||
if (ArrayUtils.isEmpty(methods)) {
|
||||
return bean;
|
||||
}
|
||||
|
||||
if (!ReflectionUtils.isPojoClass(clazz)) {
|
||||
logger.warn("The message registration class [{}] is not a POJO class, and the parent class will not be scanned", clazz);
|
||||
}
|
||||
|
||||
try {
|
||||
for (var method : methods) {
|
||||
var paramClazzs = method.getParameterTypes();
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.zfoo.protocol.xml.XmlProtocols;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -124,9 +125,8 @@ public class PacketService implements IPacketService {
|
||||
}
|
||||
|
||||
// 注册协议接收器
|
||||
var beanNames = applicationContext.getBeanDefinitionNames();
|
||||
for (var beanName : beanNames) {
|
||||
var bean = applicationContext.getBean(beanName);
|
||||
var componentBeans = applicationContext.getBeansWithAnnotation(Component.class);
|
||||
for (var bean : componentBeans.values()) {
|
||||
PacketBus.registerPacketReceiverDefinition(bean);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,11 +63,15 @@ public abstract class PacketBus {
|
||||
public static void registerPacketReceiverDefinition(Object bean) {
|
||||
var clazz = bean.getClass();
|
||||
|
||||
var methods = ReflectionUtils.getMethodsByAnnotation(clazz, PacketReceiver.class);
|
||||
var methods = ReflectionUtils.getMethodsByAnnoInPOJOClass(clazz, PacketReceiver.class);
|
||||
if (ArrayUtils.isEmpty(methods)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ReflectionUtils.isPojoClass(clazz)) {
|
||||
logger.warn("The message registration class [{}] is not a POJO class, and the parent class will not be scanned", clazz);
|
||||
}
|
||||
|
||||
for (var method : methods) {
|
||||
var paramClazzs = method.getParameterTypes();
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.core.type.ClassMetadata;
|
||||
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
|
||||
import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Modifier;
|
||||
@@ -186,11 +187,8 @@ public class OrmManager implements IOrmManager {
|
||||
@Override
|
||||
public void inject() {
|
||||
var applicationContext = OrmContext.getApplicationContext();
|
||||
var beanNames = applicationContext.getBeanDefinitionNames();
|
||||
|
||||
for (var beanName : beanNames) {
|
||||
var bean = applicationContext.getBean(beanName);
|
||||
|
||||
var componentBeans = applicationContext.getBeansWithAnnotation(Component.class);
|
||||
for (var bean : componentBeans.values()) {
|
||||
ReflectionUtils.filterFieldsInClass(bean.getClass()
|
||||
, field -> field.isAnnotationPresent(EntityCachesInjection.class)
|
||||
, field -> {
|
||||
|
||||
@@ -164,9 +164,9 @@ public abstract class ReflectionUtils {
|
||||
* @param annotation 指定注解的Class
|
||||
* @return 数组,可能长度为0
|
||||
*/
|
||||
public static Method[] getMethodsByAnnotation(Class<?> clazz, Class<? extends Annotation> annotation) {
|
||||
public static Method[] getMethodsByAnnoInPOJOClass(Class<?> clazz, Class<? extends Annotation> annotation) {
|
||||
var list = new ArrayList<Method>();
|
||||
var methods = getAllMethods(clazz);
|
||||
var methods = clazz.getDeclaredMethods();
|
||||
for (var method : methods) {
|
||||
if (method.isAnnotationPresent(annotation)) {
|
||||
list.add(method);
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.context.event.ApplicationContextEvent;
|
||||
import org.springframework.context.event.ContextClosedEvent;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
@@ -96,17 +97,18 @@ public class SchedulerContext implements ApplicationListener<ApplicationContextE
|
||||
}
|
||||
|
||||
public void inject() {
|
||||
var beanNames = applicationContext.getBeanDefinitionNames();
|
||||
for (var beanName : beanNames) {
|
||||
var bean = applicationContext.getBean(beanName);
|
||||
var componentBeans = applicationContext.getBeansWithAnnotation(Component.class);
|
||||
for (var bean : componentBeans.values()) {
|
||||
var clazz = bean.getClass();
|
||||
|
||||
var methods = ReflectionUtils.getMethodsByAnnotation(clazz, Scheduler.class);
|
||||
|
||||
var methods = ReflectionUtils.getMethodsByAnnoInPOJOClass(bean.getClass(), Scheduler.class);
|
||||
if (ArrayUtils.isEmpty(methods)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ReflectionUtils.isPojoClass(clazz)) {
|
||||
logger.warn("The message registration class [{}] is not a POJO class, and the parent class will not be scanned", clazz);
|
||||
}
|
||||
|
||||
try {
|
||||
for (var method : methods) {
|
||||
var schedulerMethod = method.getAnnotation(Scheduler.class);
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
import org.springframework.core.type.ClassMetadata;
|
||||
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -142,11 +143,8 @@ public class StorageManager implements IStorageManager {
|
||||
@Override
|
||||
public void inject() {
|
||||
var applicationContext = StorageContext.getApplicationContext();
|
||||
var beanNames = applicationContext.getBeanDefinitionNames();
|
||||
|
||||
for (var beanName : beanNames) {
|
||||
var bean = applicationContext.getBean(beanName);
|
||||
|
||||
var componentBeans = applicationContext.getBeansWithAnnotation(Component.class);
|
||||
for (var bean : componentBeans.values()) {
|
||||
ReflectionUtils.filterFieldsInClass(bean.getClass(), field -> field.isAnnotationPresent(ResInjection.class), field -> {
|
||||
Type type = field.getGenericType();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user