From ed5768da1363742eee34c6c71db010099da6fad8 Mon Sep 17 00:00:00 2001
From: ludc <pUXmgxCf6A>
Date: 星期三, 17 五月 2023 21:55:07 +0800
Subject: [PATCH] 以及发布webservice接口功能搭建,将通通用接口移植过来

---
 Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/config/VciCxfPublishConfig.java |   85 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 85 insertions(+), 0 deletions(-)

diff --git a/Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/config/VciCxfPublishConfig.java b/Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/config/VciCxfPublishConfig.java
index e69de29..0825566 100644
--- a/Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/config/VciCxfPublishConfig.java
+++ b/Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/config/VciCxfPublishConfig.java
@@ -0,0 +1,85 @@
+package com.vci.ubcs.webservice.config;
+
+import com.alibaba.cloud.commons.lang.StringUtils;
+import com.vci.ubcs.starter.web.util.ApplicationContextProvider;
+import com.vci.ubcs.starter.web.util.VciBaseUtil;
+import com.vci.ubcs.webservice.annotation.VciWebservice;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.cxf.Bus;
+import org.apache.cxf.jaxws.EndpointImpl;
+import org.springframework.aop.support.AopUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.support.DefaultListableBeanFactory;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.util.CollectionUtils;
+
+import java.util.Map;
+
+/**
+ * 鍙戝竷鏈嶅姟绫�
+ * @author weidy
+ * @date 2020/3/27
+ */
+@Configuration
+@Slf4j
+public class VciCxfPublishConfig {
+
+    /**
+     * 娉ㄥ叆cxf鐨刡us
+     */
+    @Autowired(required = false)
+    private Bus bus;
+
+
+    /**
+     * 鍙戝竷绔欑偣鏈嶅姟
+     * @return 绔欑偣鏈嶅姟
+     */
+    @Bean
+    public void autoPushCxf(){
+		log.info("寮�濮嬭繘琛岃嚜鍔ㄥ彂甯僿ebService鎺ュ彛");
+		Map<String, Object> beansWithAnnotation =   ApplicationContextProvider.getApplicationContext().getBeansWithAnnotation(VciWebservice.class);
+        if(!CollectionUtils.isEmpty(beansWithAnnotation)){
+            //鎵捐繖浜沚ean鐨�
+            beansWithAnnotation.forEach((beanName,bean)->{
+                Class<?> targetClass = AopUtils.getTargetClass(bean);
+                VciWebservice annotation = targetClass.getDeclaredAnnotation(VciWebservice.class);
+                if(annotation == null){
+                    targetClass.getAnnotation(VciWebservice.class);
+                }
+                if(annotation!=null){
+                    //鎴戜滑鍘绘壘璺緞鍜屽悕绉�
+                    String name = annotation.value();
+                    if(StringUtils.isBlank(name)){
+                        name = VciBaseUtil.toLowForFirst(targetClass.getSimpleName()).replace(".class","");
+                    }
+                    String path = annotation.path();
+                    if(StringUtils.isBlank(path)){
+                        path = "/" + name;
+                    }
+                    //娉ㄥ唽
+                    EndpointImpl endpoint = new EndpointImpl(bus,bean);
+                    endpoint.publish(path);
+					log.info(String.format("鍙戝竷鎺ュ彛鍦板潃锛歔%s]", path));
+                    registerBean(endpoint,name + "_EndPoint");
+                }
+            });
+        }
+		log.info("weBservice鎺ュ彛鑷姩鍙戝竷缁撴潫");
+    }
+
+    /**
+     *  鍔ㄦ�佹敞鍏ean
+     * @param singletonObject 娉ㄥ叆瀵硅薄
+     * @param beanName bean鍚嶇О
+     */
+    public  void registerBean(Object singletonObject,String beanName) {
+
+        //鑾峰彇BeanFactory
+        DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) ApplicationContextProvider.getApplicationContext().getAutowireCapableBeanFactory();
+
+        //鍔ㄦ�佹敞鍐宐ean.
+        defaultListableBeanFactory.registerSingleton(beanName, singletonObject);
+    }
+}

--
Gitblit v1.9.3