Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.2.x-optimize-nacos-config-anno…
Browse files Browse the repository at this point in the history
…tation' into 2.2.x-optimize-nacos-config-annotation
  • Loading branch information
shiyiyue1102 committed Nov 21, 2024
2 parents 7d784df + 1baf667 commit f21c8f1
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.alibaba.cloud.nacos.annotation;

import java.beans.PropertyDescriptor;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
Expand Down Expand Up @@ -54,6 +55,12 @@
import org.springframework.core.annotation.MergedAnnotation;
import org.springframework.core.annotation.MergedAnnotations;
import org.springframework.core.type.MethodMetadata;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.PriorityOrdered;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.util.ReflectionUtils;

public class NacosAnnotationProcessor implements BeanPostProcessor, PriorityOrdered, ApplicationContextAware {
Expand Down Expand Up @@ -113,7 +120,6 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName);
Class clazz = bean.getClass();

NacosConfig annotationBean = AnnotationUtils.findAnnotation(clazz, NacosConfig.class);
if (annotationBean != null) {
handleBeanNacosConfigAnnotation(annotationBean.dataId(), annotationBean.group(), annotationBean.key(), beanName, bean, annotationBean.defaultValue());
Expand Down Expand Up @@ -705,7 +711,6 @@ private void handleMethodAnnotation(final Object bean, String beanName, final Me
handleMethodNacosConfigListener(configAnnotation, beanName, bean, method);
return;
}

if (!applicationContext.containsBeanDefinition(beanName)) {
return;
}
Expand All @@ -725,6 +730,7 @@ private void handleMethodAnnotation(final Object bean, String beanName, final Me
}
}
}

}

@Override
Expand Down Expand Up @@ -752,4 +758,5 @@ private static String[] getNullPropertyNames(Object source) {
}
return nullPropertyNames.toArray(new String[0]);
}

}

0 comments on commit f21c8f1

Please sign in to comment.