From ed3a1614384279b7d3a97e7411b649476a934ddb Mon Sep 17 00:00:00 2001
From: duxinglangzi <871364441@qq.com>
Date: 星期二, 06 九月 2022 15:14:48 +0800
Subject: [PATCH] add LICENSE.

---
 src/main/java/com/duxinglangzi/canal/starter/configuration/CanalListenerAnnotationBeanPostProcessor.java |   22 ++++++++++++++++++----
 1 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/duxinglangzi/canal/starter/configuration/CanalListenerAnnotationBeanPostProcessor.java b/src/main/java/com/duxinglangzi/canal/starter/configuration/CanalListenerAnnotationBeanPostProcessor.java
index 617c73e..64915e4 100644
--- a/src/main/java/com/duxinglangzi/canal/starter/configuration/CanalListenerAnnotationBeanPostProcessor.java
+++ b/src/main/java/com/duxinglangzi/canal/starter/configuration/CanalListenerAnnotationBeanPostProcessor.java
@@ -11,6 +11,8 @@
 import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
 import org.springframework.beans.factory.config.BeanPostProcessor;
 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
 import org.springframework.core.MethodIntrospector;
 import org.springframework.core.annotation.AnnotatedElementUtils;
 
@@ -23,10 +25,9 @@
 
 /**
  * @author wuqiong 2022/4/11
- * @description
  */
 public class CanalListenerAnnotationBeanPostProcessor implements
-        BeanPostProcessor, SmartInitializingSingleton, BeanFactoryPostProcessor {
+        BeanPostProcessor, SmartInitializingSingleton, BeanFactoryPostProcessor, ApplicationContextAware {
 
     private static final Logger logger = LoggerFactory.getLogger(CanalListenerAnnotationBeanPostProcessor.class);
 
@@ -34,20 +35,23 @@
     private Set<CanalListenerEndpointRegistrar> registrars = Collections.newSetFromMap(new ConcurrentHashMap<>());
     private ConfigurableListableBeanFactory configurableListableBeanFactory;
     private CanalAutoConfigurationProperties canalAutoConfigurationProperties;
+    private ApplicationContext applicationContext;
 
     @Override
     public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException {
         if (notAnnotatedClasses.contains(bean.getClass())) return bean;
         Class<?> targetClass = AopUtils.getTargetClass(bean);
+        // 鍙壂鎻忕被鐨勬柟娉曪紝鐩墠 CanalListener 鍙敮鎸佸湪鏂规硶涓�
         Map<Method, CanalListener> annotatedMethods = MethodIntrospector.selectMethods(targetClass,
                 (MethodIntrospector.MetadataLookup<CanalListener>) method -> findListenerAnnotations(method));
         if (annotatedMethods.isEmpty()) {
             this.notAnnotatedClasses.add(bean.getClass());
         } else {
+            // 鍏堝姞鍏ュ埌寰呮敞鍐岄噷闈�
             annotatedMethods.entrySet().stream()
                     .filter(e -> e != null)
-                    .forEach(ele -> registrars.add(new CanalListenerEndpointRegistrar(bean, ele)));
-            logger.info("Registered @CanalListener methods processed on bean:{} , Methods :{} ", bean.getClass().getName(),
+                    .forEach(ele -> registrars.add(createRegistrar(bean, ele)));
+            logger.info("Registered @CanalListener methods processed on bean:{} , Methods :{} ", beanName,
                     annotatedMethods.keySet().stream().map(e -> e.getName()).collect(Collectors.toSet()));
         }
         return bean;
@@ -70,5 +74,15 @@
         this.configurableListableBeanFactory = configurableListableBeanFactory;
     }
 
+    @Override
+    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+        this.applicationContext = applicationContext;
+    }
 
+    private CanalListenerEndpointRegistrar createRegistrar(Object bean, Map.Entry<Method, CanalListener> entry) {
+        return new CanalListenerEndpointRegistrar(bean, entry.getKey(),
+                applicationContext.getEnvironment().resolvePlaceholders(entry.getValue().destination()),
+                applicationContext.getEnvironment().resolvePlaceholders(entry.getValue().database()),
+                entry.getValue().table(), entry.getValue().eventType());
+    }
 }

--
Gitblit v1.8.0