diff --git a/pom.xml b/pom.xml index 6e4ff453..37b31ae4 100644 --- a/pom.xml +++ b/pom.xml @@ -119,6 +119,14 @@ import + + org.springframework.cloud + spring-cloud-alibaba-dependencies + ${project.version} + pom + import + + org.springframework.cloud spring-cloud-commons-dependencies @@ -157,7 +165,6 @@ pom import - net.sourceforge.cobertura cobertura-runtime @@ -165,15 +172,6 @@ provided pom - - - org.springframework.cloud - spring-cloud-alibaba-dependencies - ${project.version} - pom - import - - @@ -211,7 +209,14 @@ org.codehaus.mojo cobertura-maven-plugin - 2.7 + ${cobertura-maven-plugin.version} + + + org.ow2.asm + asm + 5.0.3 + + true @@ -220,26 +225,6 @@ - - - org/springframework/cloud/alibaba/cloud/dependencies/**.*.class - org/springframework/cloud/alibaba/cloud/docs/**.*.class - org/springframework/cloud/alibaba/cloud/examples/**.*.class - org/springframework/cloud/alibaba/cloud/test/**.*.class - org/springframework/cloud/start/alibaba/**.*.class - org/springframework/cloud/start/alicloud/**.*.class - org/springframework/cloud/alibaba/nacos/src/test/**.*.class - org/springframework/cloud/alibaba/nacos/config/server/src/test/**.*.class - org/springframework/cloud/alibaba/sentinel/src/test/**.*.class - org/springframework/cloud/alibaba/sentinel/datasource/src/test/**.*.class - org/springframework/cloud/alicloud/acm/src/test/**.*.class - org/springframework/cloud/alicloud/ans/src/test/**.*.class - org/springframework/cloud/alicloud/context/src/test/**.*.class - org/springframework/cloud/alicloud/oss/src/test/**.*.class - org/springframework/cloud/alicloud/scx/src/test/**.*.class - org/springframework/cloud/stream/binder/rocketmq/src/test/**.*.class - - diff --git a/spring-cloud-alibaba-dependencies/pom.xml b/spring-cloud-alibaba-dependencies/pom.xml index 8e0d4305..51b95c49 100644 --- a/spring-cloud-alibaba-dependencies/pom.xml +++ b/spring-cloud-alibaba-dependencies/pom.xml @@ -17,14 +17,14 @@ Spring Cloud Alibaba Dependencies - 1.4.0 + 1.4.1 3.1.0 0.6.2 0.6.1 1.0.8 1.0.1 4.0.1 - 1.0.4 + 1.0.5 2.16.0 4.3.1 2.1.6 diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc index 324741e2..bd88310a 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/nacos-discovery.adoc @@ -260,8 +260,8 @@ public class NacosConsumerApp { @GetMapping("/echo/app-name") public String echoAppName(){ //使用 LoadBalanceClient 和 RestTemolate 结合的方式来访问 - ServiceInstance delegate = loadBalancerClient.choose("nacos-provider"); - String url = String.format("http://%s:%s/echo/%s",delegate.getHost(),delegate.getPort(),appName); + ServiceInstance serviceInstance = loadBalancerClient.choose("nacos-provider"); + String url = String.format("http://%s:%s/echo/%s",serviceInstance.getHost(),serviceInstance.getPort(),appName); System.out.println("request url:"+url); return restTemplate.getForObject(url,String.class); } diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc/nacos-discovery.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc/nacos-discovery.adoc index 03f1c3f4..44f2222f 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc/nacos-discovery.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc/nacos-discovery.adoc @@ -260,8 +260,8 @@ public class NacosConsumerApp { @GetMapping("/echo/app-name") public String echoAppName(){ //Access through the combination of LoadBalanceClient and RestTemolate - ServiceInstance delegate = loadBalancerClient.choose("nacos-provider"); - String url = String.format("http://%s:%s/echo/%s",delegate.getHost(),delegate.getPort(),appName); + ServiceInstance serviceInstance = loadBalancerClient.choose("nacos-provider"); + String url = String.format("http://%s:%s/echo/%s",serviceInstance.getHost(),serviceInstance.getPort(),appName); System.out.println("request url:" +url); return restTemplate.getForObject(url,String.class); } diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoController.java b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoController.java deleted file mode 100644 index 1a571b26..00000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoController.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.cloud.alibaba.cloud.examples; - -import com.alibaba.dubbo.config.annotation.Service; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@Service(version = "1.0.0") -public class EchoController implements EchoService { - @Override - @RequestMapping(value = "/echo/{string}", method = RequestMethod.GET) - public String echo(@PathVariable String string) { - return "hello Nacos Discovery " + string; - } - - @Override - @RequestMapping(value = "/divide", method = RequestMethod.GET) - public String divide(@RequestParam Integer a, @RequestParam Integer b) { - return String.valueOf(a / b); - } -} diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoService.java b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoService.java deleted file mode 100644 index b60affbc..00000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoService.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.cloud.alibaba.cloud.examples; - -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; - -/** - * TODO - */ -public interface EchoService { - @RequestMapping(value = "/echo/{string}", method = RequestMethod.GET) - String echo(@PathVariable String string); - - @RequestMapping(value = "/divide", method = RequestMethod.GET) - String divide(@RequestParam Integer a, @RequestParam Integer b); -} diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ProviderApplication.java b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ProviderApplication.java index 2519096a..843f5cbe 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ProviderApplication.java +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ProviderApplication.java @@ -1,30 +1,13 @@ package org.springframework.cloud.alibaba.cloud.examples; -import com.alibaba.dubbo.config.spring.ServiceBean; -import com.alibaba.dubbo.config.spring.context.event.ServiceBeanExportedEvent; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.cloud.client.discovery.event.InstancePreRegisteredEvent; -import org.springframework.cloud.client.serviceregistry.Registration; -import org.springframework.context.event.EventListener; - -import java.beans.BeanInfo; -import java.beans.Introspector; -import java.beans.PropertyDescriptor; -import java.lang.reflect.Method; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.net.URL; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.Map; - -import static org.springframework.util.ClassUtils.isPrimitiveOrWrapper; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; /** * @author xiaojing @@ -33,118 +16,20 @@ import static org.springframework.util.ClassUtils.isPrimitiveOrWrapper; @EnableDiscoveryClient public class ProviderApplication { - public static void main(String[] args) { - SpringApplication.run(ProviderApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(ProviderApplication.class, args); + } - @Autowired - private ConfigurableListableBeanFactory beanFactory; + @RestController + class EchoController { + @RequestMapping(value = "/echo/{string}", method = RequestMethod.GET) + public String echo(@PathVariable String string) { + return "hello Nacos Discovery " + string; + } - @Autowired - private ObjectMapper objectMapper; - - @EventListener(ServiceBeanExportedEvent.class) - public void onServiceBeanExportedEvent(ServiceBeanExportedEvent event) { - ServiceBean serviceBean = event.getServiceBean(); - } - - @EventListener(InstancePreRegisteredEvent.class) - public void onInstancePreRegisteredEvent(InstancePreRegisteredEvent event) throws JsonProcessingException { - Registration registration = event.getRegistration(); - Map serviceBeansMap = beanFactory.getBeansOfType(ServiceBean.class); - Map metaData = registration.getMetadata(); - String serviceBeansJson = objectMapper.writeValueAsString(services(serviceBeansMap)); - metaData.put("serviceBeans", serviceBeansJson); - } - - public Map> services(Map serviceBeansMap) { - - Map> servicesMetadata = new LinkedHashMap<>(serviceBeansMap.size()); - - for (Map.Entry entry : serviceBeansMap.entrySet()) { - - String serviceBeanName = entry.getKey(); - - ServiceBean serviceBean = entry.getValue(); - - Map serviceBeanMetadata = resolveBeanMetadata(serviceBean); - - Object service = resolveServiceBean(serviceBeanName, serviceBean); - - if (service != null) { - // Add Service implementation class - serviceBeanMetadata.put("serviceClass", service.getClass().getName()); - } - - servicesMetadata.put(serviceBeanName, serviceBeanMetadata); - - } - - return servicesMetadata; - - } - - protected Map resolveBeanMetadata(final Object bean) { - - final Map beanMetadata = new LinkedHashMap<>(); - - try { - - BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass()); - PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); - - for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { - - Method readMethod = propertyDescriptor.getReadMethod(); - - if (readMethod != null && isSimpleType(propertyDescriptor.getPropertyType())) { - - String name = Introspector.decapitalize(propertyDescriptor.getName()); - Object value = readMethod.invoke(bean); - - if (value != null) { - beanMetadata.put(name, value); - } - } - - } - - } catch (Exception e) { - throw new RuntimeException(e); - } - - return beanMetadata; - - } - - private Object resolveServiceBean(String serviceBeanName, ServiceBean serviceBean) { - - int index = serviceBeanName.indexOf("#"); - - if (index > -1) { - - Class interfaceClass = serviceBean.getInterfaceClass(); - - String serviceName = serviceBeanName.substring(index + 1); - - if (beanFactory.containsBean(serviceName)) { - return beanFactory.getBean(serviceName, interfaceClass); - } - - } - - return null; - - } - - private static boolean isSimpleType(Class type) { - return isPrimitiveOrWrapper(type) - || type == String.class - || type == BigDecimal.class - || type == BigInteger.class - || type == Date.class - || type == URL.class - || type == Class.class - ; - } + @RequestMapping(value = "/divide", method = RequestMethod.GET) + public String divide(@RequestParam Integer a, @RequestParam Integer b) { + return String.valueOf(a / b); + } + } } diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/resources/application.properties index 81cea717..66100d79 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/resources/application.properties +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/resources/application.properties @@ -1,12 +1,4 @@ server.port=18082 spring.application.name=service-provider spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 -management.endpoints.web.exposure.include=* - - -dubbo.scan.base-packages=org.springframework.cloud.alibaba.cloud.examples - -dubbo.registry.address=nacos://127.0.0.1:8848 - -dubbo.protocol.name=dubbo -dubbo.protocol.port=-1 \ No newline at end of file +management.endpoints.web.exposure.include=* \ No newline at end of file