3939import org .springframework .context .ApplicationListener ;
4040import org .springframework .context .EnvironmentAware ;
4141import org .springframework .core .MethodParameter ;
42+ import org .springframework .core .annotation .AnnotationAttributes ;
4243import org .springframework .core .env .Environment ;
4344import org .springframework .util .ReflectionUtils ;
4445
4546import com .alibaba .nacos .api .config .annotation .NacosValue ;
4647import com .alibaba .nacos .common .utils .MD5Utils ;
4748import com .alibaba .nacos .spring .context .event .config .NacosConfigReceivedEvent ;
48- import com .alibaba .spring .beans .factory .annotation .AnnotationInjectedBeanPostProcessor ;
49+ import com .alibaba .spring .beans .factory .annotation .AbstractAnnotationBeanPostProcessor ;
4950
5051/**
52+ * Injected {@link NacosValue}
5153 * {@link org.springframework.beans.factory.config.BeanPostProcessor} implementation.
5254 *
5355 * @author <a href="mailto:[email protected] ">hxy1991</a> 5456 * @see NacosValue
5557 * @since 0.1.0
5658 */
57- public class NacosValueAnnotationBeanPostProcessor extends
58- AnnotationInjectedBeanPostProcessor < NacosValue > implements BeanFactoryAware ,
59+ public class NacosValueAnnotationBeanPostProcessor
60+ extends AbstractAnnotationBeanPostProcessor implements BeanFactoryAware ,
5961 EnvironmentAware , ApplicationListener <NacosConfigReceivedEvent > {
6062
6163 /**
@@ -80,11 +82,29 @@ public class NacosValueAnnotationBeanPostProcessor extends
8082
8183 private Environment environment ;
8284
85+ public NacosValueAnnotationBeanPostProcessor () {
86+ super (NacosValue .class );
87+ }
88+
89+ @ Override
90+ public void setBeanFactory (BeanFactory beanFactory ) throws BeansException {
91+ if (!(beanFactory instanceof ConfigurableListableBeanFactory )) {
92+ throw new IllegalArgumentException (
93+ "NacosValueAnnotationBeanPostProcessor requires a ConfigurableListableBeanFactory" );
94+ }
95+ this .beanFactory = (ConfigurableListableBeanFactory ) beanFactory ;
96+ }
97+
98+ @ Override
99+ public void setEnvironment (Environment environment ) {
100+ this .environment = environment ;
101+ }
102+
83103 @ Override
84- protected Object doGetInjectedBean (NacosValue annotation , Object bean ,
104+ protected Object doGetInjectedBean (AnnotationAttributes attributes , Object bean ,
85105 String beanName , Class <?> injectedType ,
86- InjectionMetadata .InjectedElement injectedElement ) {
87- String annotationValue = annotation . value ( );
106+ InjectionMetadata .InjectedElement injectedElement ) throws Exception {
107+ String annotationValue = attributes . getString ( "value" );
88108 String value = beanFactory .resolveEmbeddedValue (annotationValue );
89109
90110 Member member = injectedElement .getMember ();
@@ -100,24 +120,10 @@ protected Object doGetInjectedBean(NacosValue annotation, Object bean,
100120 }
101121
102122 @ Override
103- protected String buildInjectedObjectCacheKey (NacosValue annotation , Object bean ,
104- String beanName , Class <?> injectedType ,
123+ protected String buildInjectedObjectCacheKey (AnnotationAttributes attributes ,
124+ Object bean , String beanName , Class <?> injectedType ,
105125 InjectionMetadata .InjectedElement injectedElement ) {
106- return bean .getClass ().getName () + annotation ;
107- }
108-
109- @ Override
110- public void setBeanFactory (BeanFactory beanFactory ) throws BeansException {
111- if (!(beanFactory instanceof ConfigurableListableBeanFactory )) {
112- throw new IllegalArgumentException (
113- "NacosValueAnnotationBeanPostProcessor requires a ConfigurableListableBeanFactory" );
114- }
115- this .beanFactory = (ConfigurableListableBeanFactory ) beanFactory ;
116- }
117-
118- @ Override
119- public void setEnvironment (Environment environment ) {
120- this .environment = environment ;
126+ return bean .getClass ().getName () + attributes ;
121127 }
122128
123129 @ Override
0 commit comments