├── config-popup-window.png ├── mconfig-popup-window.png ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── dubbo-spring-boot-actuator ├── JMX_HealthEndpoint.png ├── src │ ├── main │ │ ├── resources │ │ │ └── META-INF │ │ │ │ ├── spring.factories │ │ │ │ └── dubbo-endpoins-default.properties │ │ └── java │ │ │ └── com │ │ │ └── alibaba │ │ │ └── boot │ │ │ └── dubbo │ │ │ └── actuate │ │ │ ├── endpoint │ │ │ ├── DubboPropertiesEndpoint.java │ │ │ ├── DubboEndpoint.java │ │ │ ├── DubboServicesMetadataEndpoint.java │ │ │ ├── DubboShutdownEndpoint.java │ │ │ ├── DubboReferencesMetadataEndpoint.java │ │ │ ├── DubboConfigsMetadataEndpoint.java │ │ │ └── AbstractDubboEndpoint.java │ │ │ ├── autoconfigure │ │ │ ├── DubboHealthIndicatorAutoConfiguration.java │ │ │ └── DubboEndpointsAutoConfiguration.java │ │ │ └── health │ │ │ └── DubboHealthIndicatorProperties.java │ └── test │ │ └── java │ │ └── com │ │ └── alibaba │ │ └── boot │ │ └── dubbo │ │ └── actuate │ │ ├── endpoint │ │ └── DubboEndpointTest.java │ │ └── health │ │ └── DubboHealthIndicatorTest.java └── pom.xml ├── dubbo-spring-boot-samples ├── auto-configure-samples │ ├── consumer-sample │ │ ├── src │ │ │ └── main │ │ │ │ ├── resources │ │ │ │ └── application.yml │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── alibaba │ │ │ │ └── boot │ │ │ │ └── dubbo │ │ │ │ └── demo │ │ │ │ └── consumer │ │ │ │ └── bootstrap │ │ │ │ └── DubboAutoConfigurationConsumerBootstrap.java │ │ └── pom.xml │ ├── provider-sample │ │ ├── src │ │ │ └── main │ │ │ │ ├── resources │ │ │ │ └── application.properties │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── alibaba │ │ │ │ └── boot │ │ │ │ └── dubbo │ │ │ │ └── demo │ │ │ │ └── provider │ │ │ │ ├── service │ │ │ │ └── DefaultDemoService.java │ │ │ │ └── bootstrap │ │ │ │ └── DubboAutoConfigurationProviderBootstrap.java │ │ └── pom.xml │ └── pom.xml ├── externalized-configuration-samples │ ├── consumer-sample │ │ ├── src │ │ │ └── main │ │ │ │ ├── resources │ │ │ │ └── application.yml │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── alibaba │ │ │ │ └── boot │ │ │ │ └── dubbo │ │ │ │ └── demo │ │ │ │ └── consumer │ │ │ │ └── bootstrap │ │ │ │ └── DubboExternalizedConfigurationConsumerBootstrap.java │ │ └── pom.xml │ ├── provider-sample │ │ ├── src │ │ │ └── main │ │ │ │ ├── resources │ │ │ │ └── application.properties │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── alibaba │ │ │ │ └── boot │ │ │ │ └── dubbo │ │ │ │ └── demo │ │ │ │ └── provider │ │ │ │ ├── service │ │ │ │ └── DefaultDemoService.java │ │ │ │ └── bootstrap │ │ │ │ └── DubboExternalizedConfigurationProviderBootstrap.java │ │ └── pom.xml │ └── pom.xml ├── dubbo-registry-nacos-samples │ ├── consumer-sample │ │ ├── src │ │ │ └── main │ │ │ │ ├── resources │ │ │ │ └── application.yml │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── alibaba │ │ │ │ └── boot │ │ │ │ └── dubbo │ │ │ │ └── demo │ │ │ │ └── consumer │ │ │ │ └── bootstrap │ │ │ │ └── DubboRegistryNacosConsumerBootstrap.java │ │ └── pom.xml │ ├── provider-sample │ │ ├── src │ │ │ └── main │ │ │ │ ├── resources │ │ │ │ └── application.properties │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── alibaba │ │ │ │ └── boot │ │ │ │ └── dubbo │ │ │ │ └── demo │ │ │ │ └── provider │ │ │ │ ├── bootstrap │ │ │ │ └── DubboRegistryNacosProviderBootstrap.java │ │ │ │ └── service │ │ │ │ └── DefaultDemoService.java │ │ └── pom.xml │ └── pom.xml ├── dubbo-registry-zookeeper-samples │ ├── consumer-sample │ │ ├── src │ │ │ └── main │ │ │ │ ├── resources │ │ │ │ └── application.yml │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── alibaba │ │ │ │ └── boot │ │ │ │ └── dubbo │ │ │ │ └── demo │ │ │ │ └── consumer │ │ │ │ └── bootstrap │ │ │ │ └── DubboRegistryZooKeeperConsumerBootstrap.java │ │ └── pom.xml │ ├── provider-sample │ │ ├── src │ │ │ └── main │ │ │ │ ├── resources │ │ │ │ └── application.properties │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── alibaba │ │ │ │ └── boot │ │ │ │ └── dubbo │ │ │ │ └── demo │ │ │ │ └── provider │ │ │ │ ├── service │ │ │ │ └── DefaultDemoService.java │ │ │ │ └── bootstrap │ │ │ │ └── DubboRegistryZooKeeperProviderBootstrap.java │ │ └── pom.xml │ └── pom.xml ├── sample-api │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── alibaba │ │ │ └── boot │ │ │ └── dubbo │ │ │ └── demo │ │ │ └── consumer │ │ │ └── DemoService.java │ └── pom.xml └── pom.xml ├── .travis.yml ├── dubbo-spring-boot-autoconfigure ├── src │ ├── test │ │ ├── resources │ │ │ └── dubbo.properties │ │ └── java │ │ │ └── com │ │ │ └── alibaba │ │ │ └── boot │ │ │ └── dubbo │ │ │ ├── context │ │ │ └── event │ │ │ │ ├── WelcomeLogoApplicationListenerTest.java │ │ │ │ ├── AwaitingNonWebApplicationListenerTest.java │ │ │ │ ├── OverrideDubboConfigApplicationListenerDisableTest.java │ │ │ │ └── OverrideDubboConfigApplicationListenerTest.java │ │ │ ├── util │ │ │ ├── EnvironmentUtilsTest.java │ │ │ └── DubboUtilsTest.java │ │ │ ├── autoconfigure │ │ │ ├── RelaxedDubboConfigBinderTest.java │ │ │ └── DubboAutoConfigurationOnSingleConfigTest.java │ │ │ └── env │ │ │ └── DubboDefaultPropertiesEnvironmentPostProcessorTest.java │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ └── spring.factories │ │ └── java │ │ └── com │ │ └── alibaba │ │ └── boot │ │ └── dubbo │ │ ├── context │ │ └── event │ │ │ ├── OverrideDubboConfigApplicationListener.java │ │ │ ├── WelcomeLogoApplicationListener.java │ │ │ └── AwaitingNonWebApplicationListener.java │ │ ├── autoconfigure │ │ ├── RelaxedDubboConfigBinder.java │ │ └── DubboAutoConfiguration.java │ │ ├── util │ │ ├── EnvironmentUtils.java │ │ └── DubboUtils.java │ │ └── env │ │ └── DubboDefaultPropertiesEnvironmentPostProcessor.java └── pom.xml ├── NOTICE ├── DISCLAIMER ├── .gitignore ├── dubbo-spring-boot-distribution ├── assembly │ ├── bin-release.xml │ └── source-release.xml └── pom.xml ├── dubbo-spring-boot-starter └── pom.xml ├── mvnw.cmd ├── pom.xml └── mvnw /config-popup-window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YunaiV/incubator-dubbo-spring-boot-project/HEAD/config-popup-window.png -------------------------------------------------------------------------------- /mconfig-popup-window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YunaiV/incubator-dubbo-spring-boot-project/HEAD/mconfig-popup-window.png -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YunaiV/incubator-dubbo-spring-boot-project/HEAD/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/JMX_HealthEndpoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YunaiV/incubator-dubbo-spring-boot-project/HEAD/dubbo-spring-boot-actuator/JMX_HealthEndpoint.png -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: dubbo-auto-configure-consumer-sample -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | sudo: false # faster builds 3 | 4 | jdk: 5 | - openjdk11 6 | - oraclejdk8 7 | 8 | script: "mvn clean package" 9 | 10 | after_success: 11 | - bash <(curl -s https://codecov.io/bash) -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/test/resources/dubbo.properties: -------------------------------------------------------------------------------- 1 | dubbo.application.NAME=hello 2 | dubbo.application.owneR=world 3 | dubbo.registry.Address=10.20.153.17 4 | dubbo.protocol.pORt=20881 5 | dubbo.service.invoke.timeout=2000 -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: dubbo-externalized-configuration-consumer-sample 4 | 5 | demo: 6 | service: 7 | version: 1.0.0 8 | url: dubbo://localhost:12345 -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.alibaba.boot.dubbo.actuate.autoconfigure.DubboEndpointsAutoConfiguration,\ 3 | com.alibaba.boot.dubbo.actuate.autoconfigure.DubboHealthIndicatorAutoConfiguration -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-nacos-samples/consumer-sample/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: dubbo-registry-nacos-consumer-sample 4 | 5 | demo: 6 | service: 7 | version: 1.0.0 8 | 9 | dubbo: 10 | registry: 11 | address: nacos://127.0.0.1:8848 -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/consumer-sample/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: dubbo-registry-zookeeper-consumer-sample 4 | 5 | demo: 6 | service: 7 | version: 1.0.0 8 | 9 | embedded: 10 | zookeeper: 11 | port: 2181 12 | 13 | dubbo: 14 | registry: 15 | address: zookeeper://127.0.0.1:${embedded.zookeeper.port} -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Apache Dubbo (incubating) 2 | Copyright 2018-2019 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | 7 | This product contains code form the Netty Project: 8 | 9 | The Netty Project 10 | ================= 11 | Please visit the Netty web site for more information: 12 | * http://netty.io/ 13 | 14 | Copyright 2014 The Netty Project -------------------------------------------------------------------------------- /DISCLAIMER: -------------------------------------------------------------------------------- 1 | Apache Dubbo is an effort undergoing incubation at The Apache Software Foundation (ASF), sponsored by the Incubator. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF. -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.alibaba.boot.dubbo.autoconfigure.DubboAutoConfiguration 3 | 4 | 5 | org.springframework.context.ApplicationListener=\ 6 | com.alibaba.boot.dubbo.context.event.OverrideDubboConfigApplicationListener,\ 7 | com.alibaba.boot.dubbo.context.event.WelcomeLogoApplicationListener,\ 8 | com.alibaba.boot.dubbo.context.event.AwaitingNonWebApplicationListener 9 | 10 | org.springframework.boot.env.EnvironmentPostProcessor=\ 11 | com.alibaba.boot.dubbo.env.DubboDefaultPropertiesEnvironmentPostProcessor -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Spring boot application 2 | spring.application.name=dubbo-auto-configuration-provider-demo 3 | # Base packages to scan Dubbo Component: @com.alibaba.dubbo.config.annotation.Service 4 | dubbo.scan.base-packages=com.alibaba.boot.dubbo.demo.provider.service 5 | # Dubbo Application 6 | ## The default value of dubbo.application.name is ${spring.application.name} 7 | ## dubbo.application.name=${spring.application.name} 8 | # Dubbo Protocol 9 | dubbo.protocol.name=dubbo 10 | dubbo.protocol.port=12345 11 | ## Dubbo Registry 12 | dubbo.registry.address=N/A -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.war 15 | *.ear 16 | *.zip 17 | *.tar.gz 18 | *.rar 19 | 20 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 21 | hs_err_pid* 22 | 23 | # eclipse ignore 24 | .settings/ 25 | .project 26 | .classpath 27 | 28 | # idea ignore 29 | .idea/ 30 | *.ipr 31 | *.iml 32 | *.iws 33 | target 34 | 35 | # temp ignore 36 | *.log 37 | *.cache 38 | *.diff 39 | *.patch 40 | *.tmp 41 | 42 | # system ignore 43 | .DS_Store 44 | Thumbs.db 45 | 46 | # Maven ignore 47 | .flattened-pom.xml -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Spring boot application 2 | spring.application.name=dubbo-registry-nacos-provider-sample 3 | 4 | # Base packages to scan Dubbo Component: @com.alibaba.dubbo.config.annotation.Service 5 | dubbo.scan.base-packages=com.alibaba.boot.dubbo.demo.provider.service 6 | 7 | # Dubbo Application 8 | ## The default value of dubbo.application.name is ${spring.application.name} 9 | ## dubbo.application.name=${spring.application.name} 10 | 11 | # Dubbo Protocol 12 | dubbo.protocol.name=dubbo 13 | ## Random port 14 | dubbo.protocol.port=-1 15 | 16 | ## Dubbo Registry 17 | dubbo.registry.address=nacos://127.0.0.1:8848 18 | 19 | ## DemoService version 20 | demo.service.version=1.0.0 -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Spring boot application 2 | spring.application.name=dubbo-registry-zookeeper-provider-sample 3 | 4 | # Base packages to scan Dubbo Component: @com.alibaba.dubbo.config.annotation.Service 5 | dubbo.scan.base-packages=com.alibaba.boot.dubbo.demo.provider.service 6 | 7 | # Dubbo Application 8 | ## The default value of dubbo.application.name is ${spring.application.name} 9 | ## dubbo.application.name=${spring.application.name} 10 | 11 | embedded.zookeeper.port = 2181 12 | 13 | # Dubbo Protocol 14 | dubbo.protocol.name=dubbo 15 | ## Random port 16 | dubbo.protocol.port=-1 17 | 18 | ## Dubbo Registry 19 | dubbo.registry.address=zookeeper://127.0.0.1:${embedded.zookeeper.port} 20 | 21 | ## DemoService version 22 | demo.service.version=1.0.0 -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/sample-api/src/main/java/com/alibaba/boot/dubbo/demo/consumer/DemoService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.demo.consumer; 18 | 19 | /** 20 | * Demo Service interface 21 | * 22 | * @since 1.0.0 23 | */ 24 | public interface DemoService { 25 | 26 | String sayHello(String name); 27 | 28 | } -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/main/resources/META-INF/dubbo-endpoins-default.properties: -------------------------------------------------------------------------------- 1 | # Dubbo Endpoints Default Properties is loaded by @PropertySource with low order, 2 | # those values of properties can be override by higher PropertySource 3 | # @see DubboEndpointsAutoConfiguration 4 | 5 | # Set enabled for Dubbo Endpoints 设置 Dubbo Endpoints 是否开启 6 | management.endpoint.dubbo.enabled = true 7 | management.endpoint.dubboshutdown.enabled = false 8 | management.endpoint.dubboconfigs.enabled = true 9 | management.endpoint.dubboservices.enabled = false 10 | management.endpoint.dubboreferences.enabled = false 11 | management.endpoint.dubboproperties.enabled = true 12 | 13 | # "management.endpoints.web.base-path" should not be configured in this file 14 | 15 | # Re-defines path-mapping of Dubbo Web Endpoints 重命名 Dubbo Web Endpoints 路径 16 | management.endpoints.web.path-mapping.dubboshutdown = dubbo/shutdown 17 | management.endpoints.web.path-mapping.dubboconfigs = dubbo/configs 18 | management.endpoints.web.path-mapping.dubboservices = dubbo/services 19 | management.endpoints.web.path-mapping.dubboreferences = dubbo/references 20 | management.endpoints.web.path-mapping.dubboproperties = dubbo/properties -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Spring boot application 2 | spring.application.name=dubbo-externalized-configuration-provider-sample 3 | 4 | # Base packages to scan Dubbo Component: @com.alibaba.dubbo.config.annotation.Service 5 | dubbo.scan.base-packages=com.alibaba.boot.dubbo.demo.provider.service 6 | 7 | # Dubbo Application 8 | ## The default value of dubbo.application.name is ${spring.application.name} 9 | ## dubbo.application.name=${spring.application.name} 10 | 11 | # Dubbo Protocol 12 | dubbo.protocol.name=dubbo 13 | dubbo.protocol.port=12345 14 | 15 | ## Dubbo Registry 16 | dubbo.registry.address=N/A 17 | 18 | ## DemoService version 19 | demo.service.version=1.0.0 20 | 21 | #dubbo.config.multiple=false 22 | 23 | management.endpoint.dubbo.enabled = false 24 | management.endpoint.dubboshutdown.enabled = true 25 | management.endpoint.dubboconfigs.enabled = true 26 | management.endpoint.dubboservices.enabled = true 27 | management.endpoint.dubboreferences.enabled = true 28 | management.endpoint.dubboproperties.enabled = true 29 | 30 | management.endpoints.web.exposure.include=health,info,dubbo,dubboconfigs,dubboservices -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/sample-api/pom.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | 21 | com.alibaba.boot.samples 22 | dubbo-spring-boot-samples 23 | ${revision} 24 | ../pom.xml 25 | 26 | 4.0.0 27 | 28 | dubbo-spring-boot-sample-api 29 | Dubbo Spring Boot Samples : API 30 | 31 | -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboPropertiesEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.actuate.endpoint; 18 | 19 | import com.alibaba.boot.dubbo.util.DubboUtils; 20 | import org.springframework.boot.actuate.endpoint.annotation.Endpoint; 21 | import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; 22 | 23 | import java.util.SortedMap; 24 | 25 | /** 26 | * Dubbo Properties {@link Endpoint} 27 | * 28 | * 29 | * @since 1.0.0 30 | */ 31 | @Endpoint(id = "dubboproperties") 32 | public class DubboPropertiesEndpoint extends AbstractDubboEndpoint { 33 | 34 | @ReadOperation 35 | public SortedMap properties() { 36 | return DubboUtils.filterDubboProperties(environment); 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.demo.provider.service; 18 | 19 | import com.alibaba.boot.dubbo.demo.consumer.DemoService; 20 | import com.alibaba.dubbo.config.annotation.Service; 21 | 22 | import org.springframework.beans.factory.annotation.Value; 23 | 24 | /** 25 | * Default {@link DemoService} 26 | * 27 | * @see DemoService 28 | * @since 1.0.0 29 | */ 30 | @Service(version = "1.0.0") 31 | public class DefaultDemoService implements DemoService { 32 | 33 | /** 34 | * The default value of ${dubbo.application.name} is ${spring.application.name} 35 | */ 36 | @Value("${dubbo.application.name}") 37 | private String serviceName; 38 | 39 | @Override 40 | public String sayHello(String name) { 41 | return String.format("[%s] : Hello, %s", serviceName, name); 42 | } 43 | } -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboRegistryNacosProviderBootstrap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.demo.provider.bootstrap; 18 | 19 | import com.alibaba.boot.dubbo.demo.provider.service.DefaultDemoService; 20 | 21 | import org.springframework.boot.WebApplicationType; 22 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 23 | import org.springframework.boot.builder.SpringApplicationBuilder; 24 | 25 | /** 26 | * Dubbo Registry ZooKeeper Provider Bootstrap 27 | * 28 | * @see DefaultDemoService 29 | * @since 1.0.0 30 | */ 31 | @EnableAutoConfiguration 32 | public class DubboRegistryNacosProviderBootstrap { 33 | 34 | public static void main(String[] args) { 35 | new SpringApplicationBuilder(DubboRegistryNacosProviderBootstrap.class) 36 | .web(WebApplicationType.NONE) 37 | .run(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/auto-configure-samples/pom.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | 21 | com.alibaba.boot.samples 22 | dubbo-spring-boot-samples 23 | ${revision} 24 | ../pom.xml 25 | 26 | 4.0.0 27 | 28 | dubbo-spring-boot-auto-configure-samples 29 | Dubbo Spring Boot Samples : Auto-Configure 30 | Dubbo Spring Boot Auto-Configure Samples 31 | pom 32 | 33 | 34 | consumer-sample 35 | provider-sample 36 | 37 | 38 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.demo.provider.service; 18 | 19 | import com.alibaba.boot.dubbo.demo.consumer.DemoService; 20 | import com.alibaba.dubbo.config.annotation.Service; 21 | 22 | import org.springframework.beans.factory.annotation.Value; 23 | 24 | /** 25 | * Default {@link DemoService} 26 | * 27 | * @see DemoService 28 | * @since 1.0.0 29 | */ 30 | @Service(version = "${demo.service.version}") 31 | public class DefaultDemoService implements DemoService { 32 | 33 | /** 34 | * The default value of ${dubbo.application.name} is ${spring.application.name} 35 | */ 36 | @Value("${dubbo.application.name}") 37 | private String serviceName; 38 | 39 | @Override 40 | public String sayHello(String name) { 41 | return String.format("[%s] : Hello, %s", serviceName, name); 42 | } 43 | } -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboAutoConfigurationProviderBootstrap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.demo.provider.bootstrap; 18 | 19 | import com.alibaba.boot.dubbo.demo.provider.service.DefaultDemoService; 20 | 21 | import org.springframework.boot.WebApplicationType; 22 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 23 | import org.springframework.boot.builder.SpringApplicationBuilder; 24 | 25 | /** 26 | * Dubbo Auto-Configuration Provider Bootstrap 27 | * 28 | * @see DefaultDemoService 29 | * @since 1.0.0 30 | */ 31 | @EnableAutoConfiguration 32 | public class DubboAutoConfigurationProviderBootstrap { 33 | 34 | public static void main(String[] args) { 35 | new SpringApplicationBuilder(DubboAutoConfigurationProviderBootstrap.class) 36 | .web(WebApplicationType.NONE) 37 | .run(args); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-nacos-samples/pom.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | 21 | com.alibaba.boot.samples 22 | dubbo-spring-boot-samples 23 | ${revision} 24 | ../pom.xml 25 | 26 | 4.0.0 27 | 28 | dubbo-spring-boot-registry-nacos-samples 29 | Dubbo Spring Boot Samples : Registry Nacos 30 | Dubbo Spring Boot Registry Nacos Samples 31 | pom 32 | 33 | 34 | consumer-sample 35 | provider-sample 36 | 37 | 38 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.demo.provider.service; 18 | 19 | import com.alibaba.boot.dubbo.demo.consumer.DemoService; 20 | import com.alibaba.dubbo.config.annotation.Service; 21 | 22 | import org.springframework.beans.factory.annotation.Value; 23 | 24 | /** 25 | * Default {@link DemoService} 26 | * 27 | * @see DemoService 28 | * @since 1.0.0 29 | */ 30 | @Service(version = "${demo.service.version}") 31 | public class DefaultDemoService implements DemoService { 32 | 33 | /** 34 | * The default value of ${dubbo.application.name} is ${spring.application.name} 35 | */ 36 | @Value("${dubbo.application.name}") 37 | private String serviceName; 38 | 39 | @Override 40 | public String sayHello(String name) { 41 | return String.format("[%s] : Hello, %s", serviceName, name); 42 | } 43 | } -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.demo.provider.service; 18 | 19 | import com.alibaba.boot.dubbo.demo.consumer.DemoService; 20 | import com.alibaba.dubbo.config.annotation.Service; 21 | 22 | import org.springframework.beans.factory.annotation.Value; 23 | 24 | /** 25 | * Default {@link DemoService} 26 | * 27 | * @see DemoService 28 | * @since 1.0.0 29 | */ 30 | @Service(version = "${demo.service.version}") 31 | public class DefaultDemoService implements DemoService { 32 | 33 | /** 34 | * The default value of ${dubbo.application.name} is ${spring.application.name} 35 | */ 36 | @Value("${dubbo.application.name}") 37 | private String serviceName; 38 | 39 | @Override 40 | public String sayHello(String name) { 41 | return String.format("[%s] : Hello, %s", serviceName, name); 42 | } 43 | } -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/pom.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | 21 | com.alibaba.boot.samples 22 | dubbo-spring-boot-samples 23 | ${revision} 24 | ../pom.xml 25 | 26 | 4.0.0 27 | 28 | dubbo-spring-boot-registry-zookeeper-samples 29 | Dubbo Spring Boot Samples : Registry Zookeeper 30 | Dubbo Spring Boot Registry Zookeeper Samples 31 | pom 32 | 33 | 34 | consumer-sample 35 | provider-sample 36 | 37 | 38 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/externalized-configuration-samples/pom.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | 21 | com.alibaba.boot.samples 22 | dubbo-spring-boot-samples 23 | ${revision} 24 | ../pom.xml 25 | 26 | 4.0.0 27 | 28 | dubbo-spring-boot-externalized-configuration-samples 29 | Dubbo Spring Boot Samples : Externalized Configuration 30 | Dubbo Spring Boot Externalized Configuration Samples 31 | pom 32 | 33 | 34 | consumer-sample 35 | provider-sample 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboExternalizedConfigurationProviderBootstrap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.demo.provider.bootstrap; 18 | 19 | import com.alibaba.boot.dubbo.demo.provider.service.DefaultDemoService; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | import org.springframework.boot.builder.SpringApplicationBuilder; 22 | import org.springframework.context.ConfigurableApplicationContext; 23 | 24 | /** 25 | * Dubbo Externalized Configuration Provider Bootstrap 26 | * 27 | * @see DefaultDemoService 28 | * @since 1.0.0 29 | */ 30 | @SpringBootApplication 31 | public class DubboExternalizedConfigurationProviderBootstrap { 32 | 33 | public static void main(String[] args) throws InterruptedException { 34 | ConfigurableApplicationContext ctx = new SpringApplicationBuilder(DubboExternalizedConfigurationProviderBootstrap.class) 35 | // .web(WebApplicationType.NONE) 36 | .run(args); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/context/event/WelcomeLogoApplicationListenerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.context.event; 18 | 19 | import org.junit.Assert; 20 | import org.junit.Test; 21 | import org.junit.runner.RunWith; 22 | import org.springframework.beans.factory.annotation.Autowired; 23 | import org.springframework.boot.test.context.SpringBootTest; 24 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 25 | 26 | /** 27 | * {@link WelcomeLogoApplicationListener} Test 28 | * 29 | * 30 | * @see WelcomeLogoApplicationListener 31 | * @since 1.0.0 32 | */ 33 | @RunWith(SpringJUnit4ClassRunner.class) 34 | @SpringBootTest( 35 | classes = {WelcomeLogoApplicationListener.class} 36 | ) 37 | public class WelcomeLogoApplicationListenerTest { 38 | 39 | @Autowired 40 | private WelcomeLogoApplicationListener welcomeLogoApplicationListener; 41 | 42 | @Test 43 | public void testOnApplicationEvent() { 44 | 45 | Assert.assertNotNull(welcomeLogoApplicationListener.buildBannerText()); 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-nacos-samples/consumer-sample/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboRegistryNacosConsumerBootstrap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.demo.consumer.bootstrap; 18 | 19 | import com.alibaba.boot.dubbo.demo.consumer.DemoService; 20 | import com.alibaba.dubbo.config.annotation.Reference; 21 | 22 | import org.slf4j.Logger; 23 | import org.slf4j.LoggerFactory; 24 | import org.springframework.boot.ApplicationRunner; 25 | import org.springframework.boot.SpringApplication; 26 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 27 | import org.springframework.context.annotation.Bean; 28 | 29 | /** 30 | * Dubbo Registry Nacos Consumer Bootstrap 31 | */ 32 | @EnableAutoConfiguration 33 | public class DubboRegistryNacosConsumerBootstrap { 34 | 35 | private final Logger logger = LoggerFactory.getLogger(getClass()); 36 | 37 | @Reference(version = "${demo.service.version}") 38 | private DemoService demoService; 39 | 40 | @Bean 41 | public ApplicationRunner runner() { 42 | return args -> logger.info(demoService.sayHello("mercyblitz")); 43 | } 44 | 45 | public static void main(String[] args) { 46 | SpringApplication.run(DubboRegistryNacosConsumerBootstrap.class).close(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboAutoConfigurationConsumerBootstrap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.demo.consumer.bootstrap; 18 | 19 | import com.alibaba.boot.dubbo.demo.consumer.DemoService; 20 | import com.alibaba.dubbo.config.annotation.Reference; 21 | 22 | import org.slf4j.Logger; 23 | import org.slf4j.LoggerFactory; 24 | import org.springframework.boot.ApplicationRunner; 25 | import org.springframework.boot.SpringApplication; 26 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 27 | import org.springframework.context.annotation.Bean; 28 | 29 | /** 30 | * Dubbo Auto Configuration Consumer Bootstrap 31 | * 32 | * @since 1.0.0 33 | */ 34 | @EnableAutoConfiguration 35 | public class DubboAutoConfigurationConsumerBootstrap { 36 | 37 | private final Logger logger = LoggerFactory.getLogger(getClass()); 38 | 39 | @Reference(version = "1.0.0", url = "dubbo://localhost:12345") 40 | private DemoService demoService; 41 | 42 | @Bean 43 | public ApplicationRunner runner() { 44 | return args -> logger.info(demoService.sayHello("mercyblitz")); 45 | } 46 | 47 | public static void main(String[] args) { 48 | SpringApplication.run(DubboAutoConfigurationConsumerBootstrap.class).close(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboExternalizedConfigurationConsumerBootstrap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.demo.consumer.bootstrap; 18 | 19 | import com.alibaba.boot.dubbo.demo.consumer.DemoService; 20 | import com.alibaba.dubbo.config.annotation.Reference; 21 | 22 | import org.slf4j.Logger; 23 | import org.slf4j.LoggerFactory; 24 | import org.springframework.boot.ApplicationRunner; 25 | import org.springframework.boot.SpringApplication; 26 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 27 | import org.springframework.context.annotation.Bean; 28 | 29 | /** 30 | * Dubbo Externalized Configuration Consumer Bootstrap 31 | */ 32 | @EnableAutoConfiguration 33 | public class DubboExternalizedConfigurationConsumerBootstrap { 34 | 35 | private final Logger logger = LoggerFactory.getLogger(getClass()); 36 | 37 | @Reference(version = "${demo.service.version}", url = "${demo.service.url}") 38 | private DemoService demoService; 39 | 40 | @Bean 41 | public ApplicationRunner runner() { 42 | return args -> logger.info(demoService.sayHello("mercyblitz")); 43 | } 44 | 45 | public static void main(String[] args) { 46 | SpringApplication.run(DubboExternalizedConfigurationConsumerBootstrap.class).close(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /dubbo-spring-boot-distribution/assembly/bin-release.xml: -------------------------------------------------------------------------------- 1 | 17 | 19 | bin-release 20 | 21 | zip 22 | 23 | true 24 | ${project.build.finalName}-bin-release 25 | 26 | 27 | ../ 28 | 29 | DISCLAIMER 30 | NOTICE 31 | LICENSE 32 | 33 | 34 | 35 | 36 | 37 | 38 | true 39 | false 40 | /libs 41 | runtime 42 | 43 | com.alibaba.boot:* 44 | 45 | 46 | com.alibaba:fastjson 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/consumer-sample/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboRegistryZooKeeperConsumerBootstrap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.demo.consumer.bootstrap; 18 | 19 | import com.alibaba.boot.dubbo.demo.consumer.DemoService; 20 | import com.alibaba.dubbo.config.annotation.Reference; 21 | 22 | import org.slf4j.Logger; 23 | import org.slf4j.LoggerFactory; 24 | import org.springframework.boot.ApplicationRunner; 25 | import org.springframework.boot.SpringApplication; 26 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 27 | import org.springframework.context.annotation.Bean; 28 | 29 | /** 30 | * Dubbo Registry ZooKeeper Consumer Bootstrap 31 | */ 32 | @EnableAutoConfiguration 33 | public class DubboRegistryZooKeeperConsumerBootstrap { 34 | 35 | private final Logger logger = LoggerFactory.getLogger(getClass()); 36 | 37 | @Reference(version = "${demo.service.version}") 38 | private DemoService demoService; 39 | 40 | @Bean 41 | public ApplicationRunner runner() { 42 | return args -> logger.info(demoService.sayHello("mercyblitz")); 43 | } 44 | 45 | public static void main(String[] args) { 46 | SpringApplication.run(DubboRegistryZooKeeperConsumerBootstrap.class) // 启动 47 | .close(); // 关闭 48 | // SpringApplication.run(DubboRegistryZooKeeperConsumerBootstrap.class); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/context/event/AwaitingNonWebApplicationListenerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.context.event; 18 | 19 | import org.junit.Assert; 20 | import org.junit.Test; 21 | import org.springframework.boot.WebApplicationType; 22 | import org.springframework.boot.builder.SpringApplicationBuilder; 23 | 24 | import java.util.concurrent.atomic.AtomicBoolean; 25 | 26 | /** 27 | * {@link AwaitingNonWebApplicationListener} Test 28 | */ 29 | public class AwaitingNonWebApplicationListenerTest { 30 | 31 | @Test 32 | public void init() { 33 | AtomicBoolean awaited = AwaitingNonWebApplicationListener.getAwaited(); 34 | awaited.set(false); 35 | 36 | } 37 | 38 | @Test 39 | public void testSingleContextNonWebApplication() { 40 | new SpringApplicationBuilder(Object.class) 41 | .web(WebApplicationType.NONE) 42 | .run().close(); 43 | AtomicBoolean awaited = AwaitingNonWebApplicationListener.getAwaited(); 44 | Assert.assertTrue(awaited.get()); 45 | } 46 | 47 | @Test 48 | public void testMultipleContextNonWebApplication() { 49 | new SpringApplicationBuilder(Object.class) 50 | .parent(Object.class) 51 | .web(WebApplicationType.NONE) 52 | .run().close(); 53 | AtomicBoolean awaited = AwaitingNonWebApplicationListener.getAwaited(); 54 | Assert.assertTrue(awaited.get()); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/pom.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | 21 | com.alibaba.boot 22 | dubbo-spring-boot-parent 23 | ${revision} 24 | ../dubbo-spring-boot-parent/pom.xml 25 | 26 | 4.0.0 27 | 28 | com.alibaba.boot.samples 29 | dubbo-spring-boot-samples 30 | pom 31 | Dubbo Spring Boot Samples 32 | Dubbo Spring Boot Samples 33 | 34 | 35 | sample-api 36 | auto-configure-samples 37 | externalized-configuration-samples 38 | dubbo-registry-nacos-samples 39 | dubbo-registry-zookeeper-samples 40 | 41 | 42 | 43 | 44 | 45 | org.apache.maven.plugins 46 | maven-deploy-plugin 47 | 48 | true 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboRegistryZooKeeperProviderBootstrap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.demo.provider.bootstrap; 18 | 19 | import com.alibaba.boot.dubbo.demo.provider.service.DefaultDemoService; 20 | 21 | import org.springframework.boot.WebApplicationType; 22 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 23 | import org.springframework.boot.builder.SpringApplicationBuilder; 24 | import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; 25 | import org.springframework.context.ApplicationListener; 26 | import org.springframework.core.env.Environment; 27 | 28 | /** 29 | * Dubbo Registry ZooKeeper Provider Bootstrap 30 | * 31 | * @see DefaultDemoService 32 | * @since 1.0.0 33 | */ 34 | @EnableAutoConfiguration 35 | public class DubboRegistryZooKeeperProviderBootstrap { 36 | 37 | public static void main(String[] args) { 38 | new SpringApplicationBuilder(DubboRegistryZooKeeperProviderBootstrap.class) 39 | .web(WebApplicationType.NONE) 40 | .listeners((ApplicationListener) event -> { 41 | Environment environment = event.getEnvironment(); 42 | int port = environment.getProperty("embedded.zookeeper.port", int.class); 43 | new EmbeddedZooKeeper(port, false).start(); 44 | }) 45 | .run(args); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/util/EnvironmentUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.util; 18 | 19 | import org.junit.Assert; 20 | import org.junit.Test; 21 | import org.springframework.core.env.CompositePropertySource; 22 | import org.springframework.core.env.MapPropertySource; 23 | import org.springframework.core.env.MutablePropertySources; 24 | import org.springframework.core.env.StandardEnvironment; 25 | 26 | import java.util.HashMap; 27 | import java.util.Map; 28 | 29 | /** 30 | * {@link EnvironmentUtils} Test 31 | * 32 | * 33 | * @see EnvironmentUtils 34 | * @since 1.0.0 35 | */ 36 | public class EnvironmentUtilsTest { 37 | 38 | @Test 39 | public void testExtraProperties() { 40 | 41 | System.setProperty("user.name", "mercyblitz"); 42 | 43 | StandardEnvironment environment = new StandardEnvironment(); 44 | 45 | Map map = new HashMap<>(); 46 | 47 | map.put("user.name", "Mercy"); 48 | 49 | MapPropertySource propertySource = new MapPropertySource("first", map); 50 | 51 | CompositePropertySource compositePropertySource = new CompositePropertySource("comp"); 52 | 53 | compositePropertySource.addFirstPropertySource(propertySource); 54 | 55 | MutablePropertySources propertySources = environment.getPropertySources(); 56 | 57 | propertySources.addFirst(compositePropertySource); 58 | 59 | Map properties = EnvironmentUtils.extractProperties(environment); 60 | 61 | Assert.assertEquals("Mercy", properties.get("user.name")); 62 | 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/context/event/OverrideDubboConfigApplicationListenerDisableTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.context.event; 18 | 19 | import com.alibaba.dubbo.common.utils.ConfigUtils; 20 | 21 | import org.junit.Assert; 22 | import org.junit.BeforeClass; 23 | import org.junit.Test; 24 | import org.junit.runner.RunWith; 25 | import org.springframework.boot.test.context.SpringBootTest; 26 | import org.springframework.test.context.TestPropertySource; 27 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 28 | 29 | import java.util.Properties; 30 | 31 | /** 32 | * {@link OverrideDubboConfigApplicationListener} Test 33 | * 34 | * 35 | * @see OverrideDubboConfigApplicationListener 36 | * @since 1.0.0 37 | */ 38 | @RunWith(SpringJUnit4ClassRunner.class) 39 | @TestPropertySource( 40 | properties = { 41 | "dubbo.config.override = false", 42 | "dubbo.application.name = dubbo-demo-application", 43 | "dubbo.module.name = dubbo-demo-module", 44 | } 45 | ) 46 | @SpringBootTest( 47 | classes = {OverrideDubboConfigApplicationListener.class} 48 | ) 49 | public class OverrideDubboConfigApplicationListenerDisableTest { 50 | 51 | @BeforeClass 52 | public static void init() { 53 | ConfigUtils.getProperties().clear(); 54 | } 55 | 56 | @Test 57 | public void testOnApplicationEvent() { 58 | 59 | Properties properties = ConfigUtils.getProperties(); 60 | 61 | Assert.assertTrue(properties.isEmpty()); 62 | Assert.assertNull(properties.get("dubbo.application.name")); 63 | Assert.assertNull(properties.get("dubbo.module.name")); 64 | 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /dubbo-spring-boot-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | 21 | com.alibaba.boot 22 | dubbo-spring-boot-parent 23 | ${revision} 24 | ../dubbo-spring-boot-parent 25 | 26 | 4.0.0 27 | 28 | dubbo-spring-boot-starter 29 | jar 30 | Dubbo Spring Boot Starter 31 | Dubbo Spring Boot Starter 32 | 33 | 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter 39 | true 40 | 41 | 42 | 43 | 44 | org.apache.zookeeper 45 | zookeeper 46 | true 47 | 48 | 49 | 50 | org.apache.curator 51 | curator-framework 52 | true 53 | 54 | 55 | 56 | com.alibaba.boot 57 | dubbo-spring-boot-autoconfigure 58 | ${revision} 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /dubbo-spring-boot-distribution/assembly/source-release.xml: -------------------------------------------------------------------------------- 1 | 17 | 19 | source-release 20 | 21 | zip 22 | 23 | true 24 | ${project.build.finalName}-source-release 25 | 26 | 27 | 28 | ../ 29 | true 30 | 31 | **/* 32 | 33 | 34 | **/target/** 35 | **/build/** 36 | **/eclipse-classes/** 37 | *.enc 38 | *.gpg 39 | **/surefire* 40 | **/svn-commit* 41 | **/.idea/** 42 | **/*.iml 43 | **/*.ipr 44 | **/*.iws 45 | **/cobertura.ser 46 | **/*.log 47 | release.properties 48 | **/*.xml.* 49 | **/.mvn/** 50 | **/*.jar 51 | **/mvnw* 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/context/event/OverrideDubboConfigApplicationListenerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.context.event; 18 | 19 | import com.alibaba.dubbo.common.utils.ConfigUtils; 20 | 21 | import org.junit.Assert; 22 | import org.junit.BeforeClass; 23 | import org.junit.Test; 24 | import org.junit.runner.RunWith; 25 | import org.springframework.boot.test.context.SpringBootTest; 26 | import org.springframework.test.context.TestPropertySource; 27 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 28 | 29 | import java.util.Properties; 30 | 31 | /** 32 | * {@link OverrideDubboConfigApplicationListener} Test 33 | * 34 | * 35 | * @see OverrideDubboConfigApplicationListener 36 | * @since 1.0.0 37 | */ 38 | @RunWith(SpringJUnit4ClassRunner.class) 39 | @TestPropertySource( 40 | properties = { 41 | "dubbo.application.name = dubbo-demo-application", 42 | "dubbo.module.name = dubbo-demo-module", 43 | "dubbo.registry.address = zookeeper://192.168.99.100:32770" 44 | } 45 | ) 46 | @SpringBootTest( 47 | classes = {OverrideDubboConfigApplicationListener.class} 48 | ) 49 | public class OverrideDubboConfigApplicationListenerTest { 50 | 51 | @BeforeClass 52 | public static void init() { 53 | ConfigUtils.getProperties().clear(); 54 | } 55 | 56 | @Test 57 | public void testOnApplicationEvent() { 58 | 59 | Properties properties = ConfigUtils.getProperties(); 60 | 61 | Assert.assertEquals("dubbo-demo-application",properties.get("dubbo.application.name")); 62 | Assert.assertEquals("dubbo-demo-module",properties.get("dubbo.module.name")); 63 | Assert.assertEquals("zookeeper://192.168.99.100:32770",properties.get("dubbo.registry.address")); 64 | 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/autoconfigure/RelaxedDubboConfigBinderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.autoconfigure; 18 | 19 | import com.alibaba.dubbo.config.ApplicationConfig; 20 | import com.alibaba.dubbo.config.ProtocolConfig; 21 | import com.alibaba.dubbo.config.RegistryConfig; 22 | 23 | import org.junit.Assert; 24 | import org.junit.Test; 25 | import org.junit.runner.RunWith; 26 | import org.springframework.beans.factory.annotation.Autowired; 27 | import org.springframework.test.context.ContextConfiguration; 28 | import org.springframework.test.context.TestPropertySource; 29 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 30 | 31 | /** 32 | * {@link RelaxedDubboConfigBinder} Test 33 | * 34 | * 35 | * @since 0.1.1 36 | */ 37 | @RunWith(SpringJUnit4ClassRunner.class) 38 | @TestPropertySource(locations = "classpath:/dubbo.properties") 39 | @ContextConfiguration(classes = RelaxedDubboConfigBinder.class) 40 | public class RelaxedDubboConfigBinderTest { 41 | 42 | @Autowired 43 | private RelaxedDubboConfigBinder dubboConfigBinder; 44 | 45 | @Test 46 | public void testBinder() { 47 | 48 | ApplicationConfig applicationConfig = new ApplicationConfig(); 49 | dubboConfigBinder.bind("dubbo.application", applicationConfig); 50 | Assert.assertEquals("hello", applicationConfig.getName()); 51 | Assert.assertEquals("world", applicationConfig.getOwner()); 52 | 53 | RegistryConfig registryConfig = new RegistryConfig(); 54 | dubboConfigBinder.bind("dubbo.registry", registryConfig); 55 | Assert.assertEquals("10.20.153.17", registryConfig.getAddress()); 56 | 57 | ProtocolConfig protocolConfig = new ProtocolConfig(); 58 | dubboConfigBinder.bind("dubbo.protocol", protocolConfig); 59 | Assert.assertEquals(Integer.valueOf(20881), protocolConfig.getPort()); 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/autoconfigure/DubboHealthIndicatorAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.actuate.autoconfigure; 18 | 19 | import com.alibaba.boot.dubbo.actuate.health.DubboHealthIndicator; 20 | import com.alibaba.boot.dubbo.actuate.health.DubboHealthIndicatorProperties; 21 | import com.alibaba.boot.dubbo.autoconfigure.DubboAutoConfiguration; 22 | 23 | import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration; 24 | import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; 25 | import org.springframework.boot.actuate.health.HealthIndicator; 26 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 27 | import org.springframework.boot.autoconfigure.AutoConfigureBefore; 28 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 29 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 30 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 31 | import org.springframework.context.annotation.Bean; 32 | import org.springframework.context.annotation.Configuration; 33 | 34 | /** 35 | * Dubbo {@link DubboHealthIndicator} Auto Configuration 36 | * 37 | * 38 | * @see HealthIndicator 39 | * @since 1.0.0 40 | */ 41 | @Configuration 42 | @ConditionalOnClass({HealthIndicator.class}) // 存在 HealthIndicator 类的情况 43 | @AutoConfigureBefore({EndpointAutoConfiguration.class}) // 在 EndpointAutoConfiguration 自动配置类之前初始化 44 | @AutoConfigureAfter(DubboAutoConfiguration.class) // 在 DubboAutoConfiguration 自动配置类之后初始化 45 | @ConditionalOnEnabledHealthIndicator("dubbo") 46 | @EnableConfigurationProperties(DubboHealthIndicatorProperties.class) // 自动配置 DubboHealthIndicatorProperties 类 47 | public class DubboHealthIndicatorAutoConfiguration { 48 | 49 | @Bean 50 | @ConditionalOnMissingBean 51 | public DubboHealthIndicator dubboHealthIndicator() { 52 | return new DubboHealthIndicator(); 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.actuate.endpoint; 18 | 19 | import com.alibaba.boot.dubbo.util.DubboUtils; 20 | import com.alibaba.dubbo.common.Version; 21 | 22 | import org.springframework.boot.actuate.endpoint.annotation.Endpoint; 23 | import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; 24 | 25 | import java.util.LinkedHashMap; 26 | import java.util.Map; 27 | 28 | import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_GITHUB_URL; 29 | import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_MAILING_LIST; 30 | import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_SPRING_BOOT_GITHUB_URL; 31 | import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_SPRING_BOOT_GIT_URL; 32 | import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_SPRING_BOOT_ISSUES_URL; 33 | 34 | /** 35 | * Actuator {@link Endpoint} to expose Dubbo Meta Data 36 | * 37 | * 38 | * @see Endpoint 39 | * @since 1.0.0 40 | */ 41 | @Endpoint(id = "dubbo") 42 | public class DubboEndpoint { 43 | 44 | @ReadOperation 45 | public Map invoke() { 46 | // 创建 Map 47 | Map metaData = new LinkedHashMap<>(); 48 | 49 | // timestamp 50 | metaData.put("timestamp", System.currentTimeMillis()); 51 | 52 | // versions 53 | Map versions = new LinkedHashMap<>(); 54 | versions.put("dubbo-spring-boot", Version.getVersion(DubboUtils.class, "1.0.0")); 55 | versions.put("dubbo", Version.getVersion()); 56 | 57 | // urls 58 | Map urls = new LinkedHashMap<>(); 59 | urls.put("dubbo", DUBBO_GITHUB_URL); 60 | urls.put("mailing-list", DUBBO_MAILING_LIST); 61 | urls.put("github", DUBBO_SPRING_BOOT_GITHUB_URL); 62 | urls.put("issues", DUBBO_SPRING_BOOT_ISSUES_URL); 63 | urls.put("git", DUBBO_SPRING_BOOT_GIT_URL); 64 | 65 | metaData.put("versions", versions); 66 | metaData.put("urls", urls); 67 | return metaData; 68 | } 69 | 70 | } -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/test/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboEndpointTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.actuate.endpoint; 18 | 19 | import com.alibaba.boot.dubbo.util.DubboUtils; 20 | 21 | import org.junit.Assert; 22 | import org.junit.Test; 23 | import org.junit.runner.RunWith; 24 | import org.springframework.beans.factory.annotation.Autowired; 25 | import org.springframework.boot.test.context.SpringBootTest; 26 | import org.springframework.test.context.junit4.SpringRunner; 27 | 28 | import java.util.Map; 29 | 30 | import static com.alibaba.dubbo.common.Version.getVersion; 31 | 32 | /** 33 | * {@link DubboEndpoint} Test 34 | * 35 | * 36 | * @see DubboEndpoint 37 | * @since 1.0.0 38 | */ 39 | @RunWith(SpringRunner.class) 40 | @SpringBootTest( 41 | classes = { 42 | DubboEndpoint.class 43 | } 44 | ) 45 | public class DubboEndpointTest { 46 | 47 | 48 | @Autowired 49 | private DubboEndpoint dubboEndpoint; 50 | 51 | @Test 52 | public void testInvoke() { 53 | 54 | Map metadata = dubboEndpoint.invoke(); 55 | 56 | Assert.assertNotNull(metadata.get("timestamp")); 57 | 58 | Map versions = (Map) metadata.get("versions"); 59 | Map urls = (Map) metadata.get("urls"); 60 | 61 | Assert.assertFalse(versions.isEmpty()); 62 | Assert.assertFalse(urls.isEmpty()); 63 | 64 | Assert.assertEquals(getVersion(DubboUtils.class, "1.0.0"), versions.get("dubbo-spring-boot")); 65 | Assert.assertEquals(getVersion(), versions.get("dubbo")); 66 | 67 | Assert.assertEquals("https://github.com/apache/incubator-dubbo", urls.get("dubbo")); 68 | Assert.assertEquals("dev@dubbo.apache.org", urls.get("mailing-list")); 69 | Assert.assertEquals("https://github.com/apache/incubator-dubbo-spring-boot-project", urls.get("github")); 70 | Assert.assertEquals("https://github.com/apache/incubator-dubbo-spring-boot-project/issues", urls.get("issues")); 71 | Assert.assertEquals("https://github.com/apache/incubator-dubbo-spring-boot-project.git", urls.get("git")); 72 | 73 | } 74 | 75 | 76 | } 77 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | 21 | com.alibaba.boot.samples 22 | dubbo-spring-boot-auto-configure-samples 23 | ${revision} 24 | ../pom.xml 25 | 26 | 4.0.0 27 | 28 | dubbo-spring-boot-auto-configure-consumer-sample 29 | Dubbo Spring Boot Samples : Auto-Configure :: Consumer Sample 30 | 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter 36 | 37 | 38 | 39 | com.alibaba.boot 40 | dubbo-spring-boot-starter 41 | ${revision} 42 | 43 | 44 | 45 | com.alibaba 46 | dubbo 47 | 48 | 49 | 50 | com.alibaba.boot.samples 51 | dubbo-spring-boot-sample-api 52 | ${revision} 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-maven-plugin 62 | ${spring-boot.version} 63 | 64 | 65 | 66 | repackage 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/auto-configure-samples/provider-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | 21 | com.alibaba.boot.samples 22 | dubbo-spring-boot-auto-configure-samples 23 | ${revision} 24 | ../pom.xml 25 | 26 | 4.0.0 27 | 28 | dubbo-spring-boot-auto-configure-provider-sample 29 | Dubbo Spring Boot Samples : Auto-Configure :: Provider Sample 30 | 31 | 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter 37 | 38 | 39 | 40 | com.alibaba.boot 41 | dubbo-spring-boot-starter 42 | ${revision} 43 | 44 | 45 | 46 | com.alibaba 47 | dubbo 48 | 49 | 50 | 51 | com.alibaba.boot.samples 52 | dubbo-spring-boot-sample-api 53 | ${revision} 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | org.springframework.boot 62 | spring-boot-maven-plugin 63 | ${spring-boot.version} 64 | 65 | 66 | 67 | repackage 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | 21 | com.alibaba.boot.samples 22 | dubbo-spring-boot-externalized-configuration-samples 23 | ${revision} 24 | ../pom.xml 25 | 26 | 4.0.0 27 | 28 | dubbo-spring-boot-externalized-configuration-consumer-sample 29 | Dubbo Spring Boot Samples : Externalized Configuration :: Consumer Sample 30 | 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter 36 | 37 | 38 | 39 | com.alibaba.boot 40 | dubbo-spring-boot-starter 41 | ${revision} 42 | 43 | 44 | 45 | com.alibaba 46 | dubbo 47 | 48 | 49 | 50 | com.alibaba.boot.samples 51 | dubbo-spring-boot-sample-api 52 | ${revision} 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-maven-plugin 62 | ${spring-boot.version} 63 | 64 | 65 | 66 | repackage 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/pom.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | 21 | com.alibaba.boot 22 | dubbo-spring-boot-parent 23 | ${revision} 24 | ../dubbo-spring-boot-parent/pom.xml 25 | 26 | 4.0.0 27 | 28 | dubbo-spring-boot-autoconfigure 29 | jar 30 | Dubbo Spring Boot Auto-Configure 31 | Dubbo Spring Boot Auto-Configure 32 | 33 | 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-autoconfigure 39 | true 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-logging 45 | true 46 | 47 | 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-configuration-processor 52 | true 53 | 54 | 55 | 56 | 57 | com.alibaba 58 | dubbo 59 | true 60 | 61 | 62 | 63 | 64 | com.alibaba.spring 65 | spring-context-support 66 | 67 | 68 | 69 | 70 | org.springframework.boot 71 | spring-boot-starter-test 72 | test 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/consumer-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | 21 | com.alibaba.boot.samples 22 | dubbo-spring-boot-registry-zookeeper-samples 23 | ${revision} 24 | ../pom.xml 25 | 26 | 4.0.0 27 | 28 | dubbo-spring-boot-registry-zookeeper-consumer-sample 29 | Dubbo Spring Boot Samples : Registry Zookeeper :: Consumer Sample 30 | 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter 36 | 37 | 38 | 39 | com.alibaba.boot 40 | dubbo-spring-boot-starter 41 | ${revision} 42 | 43 | 44 | 45 | com.alibaba 46 | dubbo 47 | 48 | 49 | 50 | com.alibaba.boot.samples 51 | dubbo-spring-boot-sample-api 52 | ${revision} 53 | 54 | 55 | 56 | org.apache.curator 57 | curator-framework 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | org.springframework.boot 66 | spring-boot-maven-plugin 67 | ${spring-boot.version} 68 | 69 | 70 | 71 | repackage 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/pom.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | 21 | dubbo-spring-boot-parent 22 | com.alibaba.boot 23 | ${revision} 24 | ../dubbo-spring-boot-parent/pom.xml 25 | 26 | 4.0.0 27 | 28 | dubbo-spring-boot-actuator 29 | jar 30 | Dubbo Spring Boot Actuator 31 | Dubbo Spring Boot Actuator 32 | 33 | 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-web 38 | true 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-starter-actuator 44 | true 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-autoconfigure 50 | true 51 | 52 | 53 | 54 | 55 | org.springframework.boot 56 | spring-boot-configuration-processor 57 | true 58 | 59 | 60 | 61 | 62 | com.alibaba.boot 63 | dubbo-spring-boot-autoconfigure 64 | ${revision} 65 | 66 | 67 | 68 | 69 | com.alibaba 70 | dubbo 71 | true 72 | 73 | 74 | 75 | 76 | org.springframework.boot 77 | spring-boot-starter-test 78 | test 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboServicesMetadataEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.actuate.endpoint; 18 | 19 | import com.alibaba.dubbo.config.annotation.Service; 20 | import com.alibaba.dubbo.config.spring.ServiceBean; 21 | 22 | import org.springframework.boot.actuate.endpoint.annotation.Endpoint; 23 | import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; 24 | 25 | import java.util.LinkedHashMap; 26 | import java.util.Map; 27 | 28 | /** 29 | * Dubbo {@link Service} Metadata {@link Endpoint} 30 | * 31 | * 32 | * @since 0.2.0 33 | */ 34 | @Endpoint(id = "dubboservices") 35 | public class DubboServicesMetadataEndpoint extends AbstractDubboEndpoint { 36 | 37 | @ReadOperation 38 | public Map> services() { 39 | // 获得所有的 ServiceBean 40 | Map serviceBeansMap = super.getServiceBeansMap(); 41 | // 创建 Map 42 | // KEY:Bean 的名字 43 | // VALUE:Bean 的元数据 44 | Map> servicesMetadata = new LinkedHashMap<>(serviceBeansMap.size()); 45 | 46 | // 遍历 serviceBeansMap 元素 47 | for (Map.Entry entry : serviceBeansMap.entrySet()) { 48 | // 获得 Bean 的名字 49 | String serviceBeanName = entry.getKey(); 50 | // 获得 ServiceBean 对象 51 | ServiceBean serviceBean = entry.getValue(); 52 | // 获得 Bean 的元数据 53 | Map serviceBeanMetadata = super.resolveBeanMetadata(serviceBean); 54 | // 获得 Service 对象。若获得到,则添加到 serviceBeanMetadata 中 55 | Object service = resolveServiceBean(serviceBeanName, serviceBean); 56 | if (service != null) { 57 | // Add Service implementation class 58 | serviceBeanMetadata.put("serviceClass", service.getClass().getName()); 59 | } 60 | // 添加到 servicesMetadata 中 61 | servicesMetadata.put(serviceBeanName, serviceBeanMetadata); 62 | } 63 | return servicesMetadata; 64 | } 65 | 66 | private Object resolveServiceBean(String serviceBeanName, ServiceBean serviceBean) { 67 | int index = serviceBeanName.indexOf("#"); 68 | if (index > -1) { 69 | Class interfaceClass = serviceBean.getInterfaceClass(); 70 | String serviceName = serviceBeanName.substring(index + 1); 71 | if (applicationContext.containsBean(serviceName)) { 72 | return applicationContext.getBean(serviceName, interfaceClass); 73 | } 74 | } 75 | return null; 76 | } 77 | 78 | } -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | 21 | com.alibaba.boot.samples 22 | dubbo-spring-boot-registry-zookeeper-samples 23 | ${revision} 24 | ../pom.xml 25 | 26 | 4.0.0 27 | 28 | dubbo-spring-boot-registry-zookeeper-provider-sample 29 | Dubbo Spring Boot Samples : Registry Zookeeper :: Provider Sample 30 | 31 | 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter 37 | 38 | 39 | 40 | com.alibaba.boot 41 | dubbo-spring-boot-starter 42 | ${revision} 43 | 44 | 45 | 46 | 47 | com.alibaba 48 | dubbo 49 | 50 | 51 | 52 | com.alibaba.boot.samples 53 | dubbo-spring-boot-sample-api 54 | ${revision} 55 | 56 | 57 | 58 | 59 | org.apache.zookeeper 60 | zookeeper 61 | 62 | 63 | 64 | org.apache.curator 65 | curator-framework 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | org.springframework.boot 74 | spring-boot-maven-plugin 75 | ${spring-boot.version} 76 | 77 | 78 | 79 | repackage 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | 21 | com.alibaba.boot.samples 22 | dubbo-spring-boot-externalized-configuration-samples 23 | ${revision} 24 | ../pom.xml 25 | 26 | 4.0.0 27 | 28 | dubbo-spring-boot-externalized-configuration-provider-sample 29 | Dubbo Spring Boot Samples : Externalized Configuration :: Provider Sample 30 | 31 | 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-web 37 | 38 | 39 | 40 | com.alibaba.boot 41 | dubbo-spring-boot-starter 42 | ${revision} 43 | 44 | 45 | 46 | com.alibaba 47 | dubbo 48 | 49 | 50 | 51 | com.alibaba.boot.samples 52 | dubbo-spring-boot-sample-api 53 | ${revision} 54 | 55 | 56 | 57 | org.springframework.boot 58 | spring-boot-starter-actuator 59 | 60 | 61 | com.alibaba.boot 62 | dubbo-spring-boot-actuator 63 | 0.2.1 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | org.springframework.boot 72 | spring-boot-maven-plugin 73 | ${spring-boot.version} 74 | 75 | 76 | 77 | repackage 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboShutdownEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.actuate.endpoint; 18 | 19 | import com.alibaba.dubbo.config.ProtocolConfig; 20 | import com.alibaba.dubbo.config.spring.ServiceBean; 21 | import com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor; 22 | import com.alibaba.dubbo.registry.support.AbstractRegistryFactory; 23 | import org.springframework.boot.actuate.endpoint.annotation.Endpoint; 24 | import org.springframework.boot.actuate.endpoint.annotation.WriteOperation; 25 | 26 | import java.util.LinkedHashMap; 27 | import java.util.Map; 28 | import java.util.TreeMap; 29 | 30 | /** 31 | * Dubbo Shutdown 32 | * 33 | * @since 0.2.0 34 | */ 35 | @Endpoint(id = "dubboshutdown") 36 | public class DubboShutdownEndpoint extends AbstractDubboEndpoint { 37 | 38 | @WriteOperation 39 | public Map shutdown() throws Exception { 40 | // 创建 Map 41 | Map shutdownCountData = new LinkedHashMap<>(); 42 | 43 | // registries 44 | // 获得注册的数量 45 | int registriesCount = AbstractRegistryFactory.getRegistries().size(); 46 | // protocols 47 | // 获得 Protocol 的数量 48 | int protocolsCount = super.getProtocolConfigsBeanMap().size(); 49 | // 销毁 ProtocolConfig 50 | ProtocolConfig.destroyAll(); 51 | // 添加到 shutdownCountData 中 52 | shutdownCountData.put("registries", registriesCount); 53 | shutdownCountData.put("protocols", protocolsCount); 54 | 55 | // Service Beans 56 | // 获得所有 ServiceBean ,然后逐个销毁 57 | Map serviceBeansMap = super.getServiceBeansMap(); 58 | if (!serviceBeansMap.isEmpty()) { 59 | for (ServiceBean serviceBean : serviceBeansMap.values()) { 60 | serviceBean.destroy(); 61 | } 62 | } 63 | // 添加到 shutdownCountData 中 64 | shutdownCountData.put("services", serviceBeansMap.size()); 65 | 66 | // Reference Beans 67 | // 获得 ReferenceAnnotationBeanPostProcessor 对象 68 | ReferenceAnnotationBeanPostProcessor beanPostProcessor = super.getReferenceAnnotationBeanPostProcessor(); 69 | // 获得 Reference Bean 的数量 70 | int referencesCount = beanPostProcessor.getReferenceBeans().size(); 71 | // 销毁所有 Reference Bean 72 | beanPostProcessor.destroy(); 73 | // 添加到 shutdownCountData 中 74 | shutdownCountData.put("references", referencesCount); 75 | 76 | // Set Result to complete 77 | Map shutdownData = new TreeMap<>(); 78 | shutdownData.put("shutdown.count", shutdownCountData); 79 | return shutdownData; 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/autoconfigure/DubboEndpointsAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.actuate.autoconfigure; 18 | 19 | import com.alibaba.boot.dubbo.actuate.endpoint.DubboConfigsMetadataEndpoint; 20 | import com.alibaba.boot.dubbo.actuate.endpoint.DubboEndpoint; 21 | import com.alibaba.boot.dubbo.actuate.endpoint.DubboPropertiesEndpoint; 22 | import com.alibaba.boot.dubbo.actuate.endpoint.DubboReferencesMetadataEndpoint; 23 | import com.alibaba.boot.dubbo.actuate.endpoint.DubboServicesMetadataEndpoint; 24 | import com.alibaba.boot.dubbo.actuate.endpoint.DubboShutdownEndpoint; 25 | 26 | import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint; 27 | import org.springframework.boot.actuate.endpoint.annotation.Endpoint; 28 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 29 | import org.springframework.context.annotation.Bean; 30 | import org.springframework.context.annotation.Configuration; 31 | import org.springframework.context.annotation.PropertySource; 32 | 33 | /** 34 | * Dubbo {@link Endpoint} Auto-{@link Configuration} 35 | * 36 | * 37 | * @see Endpoint 38 | * @see Configuration 39 | * @since 0.2.0 40 | */ 41 | @Configuration 42 | @PropertySource( 43 | name = "Dubbo Endpoints Default Properties", 44 | value = "classpath:/META-INF/dubbo-endpoins-default.properties") // 导入该配置文件 45 | public class DubboEndpointsAutoConfiguration { 46 | 47 | @Bean 48 | @ConditionalOnMissingBean 49 | @ConditionalOnEnabledEndpoint 50 | public DubboEndpoint dubboEndpoint() { 51 | return new DubboEndpoint(); 52 | } 53 | 54 | @Bean 55 | @ConditionalOnMissingBean 56 | @ConditionalOnEnabledEndpoint 57 | public DubboConfigsMetadataEndpoint dubboConfigsMetadataEndpoint() { 58 | return new DubboConfigsMetadataEndpoint(); 59 | } 60 | 61 | @Bean 62 | @ConditionalOnMissingBean 63 | @ConditionalOnEnabledEndpoint 64 | public DubboPropertiesEndpoint dubboPropertiesEndpoint() { 65 | return new DubboPropertiesEndpoint(); 66 | } 67 | 68 | @Bean 69 | @ConditionalOnMissingBean 70 | @ConditionalOnEnabledEndpoint 71 | public DubboReferencesMetadataEndpoint dubboReferencesMetadataEndpoint() { 72 | return new DubboReferencesMetadataEndpoint(); 73 | } 74 | 75 | @Bean 76 | @ConditionalOnMissingBean 77 | @ConditionalOnEnabledEndpoint 78 | public DubboServicesMetadataEndpoint dubboServicesMetadataEndpoint() { 79 | return new DubboServicesMetadataEndpoint(); 80 | } 81 | 82 | @Bean 83 | @ConditionalOnMissingBean 84 | @ConditionalOnEnabledEndpoint 85 | public DubboShutdownEndpoint dubboShutdownEndpoint() { 86 | return new DubboShutdownEndpoint(); 87 | } 88 | 89 | } -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/context/event/OverrideDubboConfigApplicationListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.context.event; 18 | 19 | import com.alibaba.dubbo.common.utils.ConfigUtils; 20 | import com.alibaba.dubbo.config.AbstractConfig; 21 | 22 | import org.slf4j.Logger; 23 | import org.slf4j.LoggerFactory; 24 | import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; 25 | import org.springframework.context.ApplicationListener; 26 | import org.springframework.core.annotation.Order; 27 | import org.springframework.core.env.ConfigurableEnvironment; 28 | import org.springframework.core.env.Environment; 29 | 30 | import java.util.SortedMap; 31 | 32 | import static com.alibaba.boot.dubbo.util.DubboUtils.DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE; 33 | import static com.alibaba.boot.dubbo.util.DubboUtils.OVERRIDE_CONFIG_PROPERTY_NAME; 34 | import static com.alibaba.boot.dubbo.util.DubboUtils.filterDubboProperties; 35 | 36 | /** 37 | * {@link ApplicationListener} to override the dubbo properties from {@link Environment}into 38 | * {@link ConfigUtils#getProperties() Dubbo Config}. 39 | * {@link AbstractConfig Dubbo Config} on {@link ApplicationEnvironmentPreparedEvent}. 40 | *

41 | * 42 | * @see ConfigUtils 43 | * @since 1.0.0 44 | */ 45 | @Order // LOWEST_PRECEDENCE Make sure last execution 46 | public class OverrideDubboConfigApplicationListener implements ApplicationListener { 47 | 48 | @Override 49 | public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { 50 | // 获得 Logger 对象 51 | /** 52 | * Gets Logger After LoggingSystem configuration ready 53 | * @see LoggingApplicationListener 54 | */ 55 | final Logger logger = LoggerFactory.getLogger(getClass()); 56 | 57 | // 获得 "dubbo.config.override" 属性对应的值。默认情况下为 true 58 | ConfigurableEnvironment environment = event.getEnvironment(); 59 | boolean override = environment.getProperty(OVERRIDE_CONFIG_PROPERTY_NAME, boolean.class, DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE); 60 | // 如果要重写,则覆盖添加到 Dubbo Properties 中 61 | if (override) { 62 | // 从 environment 中,提取 "dubbo." 开头的配置 63 | SortedMap dubboProperties = filterDubboProperties(environment); 64 | // 添加到 Dubbo Properties 中 65 | ConfigUtils.getProperties().putAll(dubboProperties); 66 | if (logger.isInfoEnabled()) { 67 | logger.info("Dubbo Config was overridden by externalized configuration {}", dubboProperties); 68 | } 69 | } else { 70 | if (logger.isInfoEnabled()) { 71 | logger.info("Disable override Dubbo Config caused by property {} = {}", OVERRIDE_CONFIG_PROPERTY_NAME, override); 72 | } 73 | } 74 | 75 | } 76 | 77 | } -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-nacos-samples/consumer-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | 21 | com.alibaba.boot.samples 22 | dubbo-spring-boot-registry-nacos-samples 23 | ${revision} 24 | ../pom.xml 25 | 26 | 4.0.0 27 | 28 | dubbo-spring-boot-registry-nacos-consumer-sample 29 | Dubbo Spring Boot Samples : Registry Nacos :: Consumer Sample 30 | 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter 36 | 37 | 38 | 39 | com.alibaba.boot 40 | dubbo-spring-boot-starter 41 | ${revision} 42 | 43 | 44 | 45 | 46 | com.alibaba 47 | dubbo 48 | 49 | 50 | 51 | com.alibaba.boot.samples 52 | dubbo-spring-boot-sample-api 53 | ${revision} 54 | 55 | 56 | 57 | 58 | io.netty 59 | netty-all 60 | 61 | 62 | 63 | 64 | com.alibaba 65 | dubbo-registry-nacos 66 | 67 | 68 | 69 | 70 | com.alibaba.nacos 71 | nacos-client 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | org.springframework.boot 80 | spring-boot-maven-plugin 81 | ${spring-boot.version} 82 | 83 | 84 | 85 | repackage 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | 21 | com.alibaba.boot.samples 22 | dubbo-spring-boot-registry-nacos-samples 23 | ${revision} 24 | ../pom.xml 25 | 26 | 4.0.0 27 | 28 | dubbo-spring-boot-registry-nacos-provider-sample 29 | Dubbo Spring Boot Samples : Registry Nacos :: Provider Sample 30 | 31 | 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-web 37 | 38 | 39 | 40 | com.alibaba.boot 41 | dubbo-spring-boot-starter 42 | ${revision} 43 | 44 | 45 | 46 | 47 | com.alibaba 48 | dubbo 49 | 50 | 51 | 52 | com.alibaba.boot.samples 53 | dubbo-spring-boot-sample-api 54 | ${revision} 55 | 56 | 57 | 58 | 59 | io.netty 60 | netty-all 61 | 62 | 63 | 64 | 65 | com.alibaba 66 | dubbo-registry-nacos 67 | 68 | 69 | 70 | 71 | com.alibaba.nacos 72 | nacos-client 73 | 74 | 75 | 76 | 77 | 78 | 79 | org.springframework.boot 80 | spring-boot-maven-plugin 81 | ${spring-boot.version} 82 | 83 | 84 | 85 | repackage 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboReferencesMetadataEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.actuate.endpoint; 18 | 19 | import com.alibaba.dubbo.config.annotation.Reference; 20 | import com.alibaba.dubbo.config.spring.ReferenceBean; 21 | import com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor; 22 | 23 | import org.springframework.beans.factory.annotation.InjectionMetadata; 24 | import org.springframework.boot.actuate.endpoint.annotation.Endpoint; 25 | import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; 26 | 27 | import java.util.LinkedHashMap; 28 | import java.util.Map; 29 | 30 | /** 31 | * Dubbo {@link Reference} Metadata {@link Endpoint} 32 | * 33 | * 34 | * @since 1.0.0 35 | */ 36 | @Endpoint(id = "dubboreferences") 37 | public class DubboReferencesMetadataEndpoint extends AbstractDubboEndpoint { 38 | 39 | @ReadOperation 40 | public Map> references() { 41 | // 创建 Map 42 | // KEY:Bean 的名字 43 | // VALUE:Bean 的元数据 44 | Map> referencesMetadata = new LinkedHashMap<>(); 45 | 46 | // 获得 ReferenceAnnotationBeanPostProcessor Bean 对象 47 | ReferenceAnnotationBeanPostProcessor beanPostProcessor = super.getReferenceAnnotationBeanPostProcessor(); 48 | 49 | // injected Field ReferenceBean Cache 50 | referencesMetadata.putAll(buildReferencesMetadata(beanPostProcessor.getInjectedFieldReferenceBeanMap())); 51 | // injected Method ReferenceBean Cache 52 | referencesMetadata.putAll(buildReferencesMetadata(beanPostProcessor.getInjectedMethodReferenceBeanMap())); 53 | return referencesMetadata; 54 | } 55 | 56 | private Map> buildReferencesMetadata(Map> injectedElementReferenceBeanMap) { 57 | // 创建 Map 58 | // KEY:Bean 的名字 59 | // VALUE:Bean 的元数据 60 | Map> referencesMetadata = new LinkedHashMap<>(); 61 | // 遍历 injectedElementReferenceBeanMap 元素 62 | for (Map.Entry> entry : injectedElementReferenceBeanMap.entrySet()) { 63 | InjectionMetadata.InjectedElement injectedElement = entry.getKey(); 64 | // 获得 ReferenceBean 对象 65 | ReferenceBean referenceBean = entry.getValue(); 66 | // 获得 Bean 元数据 67 | Map beanMetadata = super.resolveBeanMetadata(referenceBean); 68 | // 获得 invoker 属性 69 | beanMetadata.put("invoker", super.resolveBeanMetadata(referenceBean.get())); 70 | // 添加到 referencesMetadata 中 71 | referencesMetadata.put(String.valueOf(injectedElement.getMember()), beanMetadata); 72 | } 73 | return referencesMetadata; 74 | } 75 | 76 | } -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/test/java/com/alibaba/boot/dubbo/actuate/health/DubboHealthIndicatorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.actuate.health; 18 | 19 | import com.alibaba.dubbo.config.spring.context.annotation.EnableDubboConfig; 20 | 21 | import org.junit.Assert; 22 | import org.junit.Test; 23 | import org.junit.runner.RunWith; 24 | import org.springframework.beans.factory.annotation.Autowired; 25 | import org.springframework.boot.actuate.health.Health; 26 | import org.springframework.boot.actuate.health.Status; 27 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 28 | import org.springframework.boot.test.context.SpringBootTest; 29 | import org.springframework.test.context.TestPropertySource; 30 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 31 | 32 | import java.util.Map; 33 | 34 | /** 35 | * {@link DubboHealthIndicator} Test 36 | * 37 | * 38 | * @see DubboHealthIndicator 39 | * @since 1.0.0 40 | */ 41 | @RunWith(SpringJUnit4ClassRunner.class) 42 | @TestPropertySource(properties = { 43 | "dubbo.protocol.id = dubbo-protocol", 44 | "dubbo.protocol.name = dubbo", 45 | "dubbo.protocol.port = 12345", 46 | "dubbo.protocol.status = registry", 47 | "dubbo.provider.id = dubbo-provider", 48 | "dubbo.provider.status = server", 49 | "management.health.dubbo.status.defaults = memory", 50 | "management.health.dubbo.status.extras = load,threadpool" 51 | }) 52 | @SpringBootTest( 53 | classes = { 54 | DubboHealthIndicator.class, 55 | DubboHealthIndicatorTest.class 56 | } 57 | ) 58 | @EnableConfigurationProperties(DubboHealthIndicatorProperties.class) 59 | @EnableDubboConfig 60 | public class DubboHealthIndicatorTest { 61 | 62 | @Autowired 63 | private DubboHealthIndicator dubboHealthIndicator; 64 | 65 | @Test 66 | public void testResolveStatusCheckerNamesMap() { 67 | 68 | Map statusCheckerNamesMap = dubboHealthIndicator.resolveStatusCheckerNamesMap(); 69 | 70 | Assert.assertEquals(5, statusCheckerNamesMap.size()); 71 | 72 | Assert.assertEquals("dubbo-protocol@ProtocolConfig.getStatus()", statusCheckerNamesMap.get("registry")); 73 | Assert.assertEquals("dubbo-provider@ProviderConfig.getStatus()", statusCheckerNamesMap.get("server")); 74 | Assert.assertEquals("management.health.dubbo.status.defaults", statusCheckerNamesMap.get("memory")); 75 | Assert.assertEquals("management.health.dubbo.status.extras", statusCheckerNamesMap.get("load")); 76 | Assert.assertEquals("management.health.dubbo.status.extras", statusCheckerNamesMap.get("threadpool")); 77 | 78 | } 79 | 80 | @Test 81 | public void testHealth() { 82 | 83 | Health health = dubboHealthIndicator.health(); 84 | 85 | Assert.assertEquals(Status.UNKNOWN, health.getStatus()); 86 | 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboConfigsMetadataEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.actuate.endpoint; 18 | 19 | import com.alibaba.dubbo.config.*; 20 | import org.springframework.beans.factory.BeanFactoryUtils; 21 | import org.springframework.boot.actuate.endpoint.annotation.Endpoint; 22 | import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; 23 | 24 | import java.util.LinkedHashMap; 25 | import java.util.Map; 26 | import java.util.TreeMap; 27 | 28 | /** 29 | * Dubbo Configs Metadata {@link Endpoint} 30 | * 31 | * 32 | * @since 0.2.0 33 | */ 34 | @Endpoint(id = "dubboconfigs") 35 | public class DubboConfigsMetadataEndpoint extends AbstractDubboEndpoint { 36 | 37 | @ReadOperation 38 | public Map>> configs() { 39 | // 创建 Map 40 | // KEY:获得类的简称。例如:ApplicationConfig、ConsumerConfig 41 | // KEY2:Bean 的名称 42 | // VALUE:Bean 的元数据 43 | Map>> configsMap = new LinkedHashMap<>(); 44 | 45 | // 遍历每个配置类,添加其的 Bean 们,到 configsMap 中 46 | addDubboConfigBeans(ApplicationConfig.class, configsMap); 47 | addDubboConfigBeans(ConsumerConfig.class, configsMap); 48 | addDubboConfigBeans(MethodConfig.class, configsMap); 49 | addDubboConfigBeans(ModuleConfig.class, configsMap); 50 | addDubboConfigBeans(MonitorConfig.class, configsMap); 51 | addDubboConfigBeans(ProtocolConfig.class, configsMap); 52 | addDubboConfigBeans(ProviderConfig.class, configsMap); 53 | addDubboConfigBeans(ReferenceConfig.class, configsMap); 54 | addDubboConfigBeans(RegistryConfig.class, configsMap); 55 | addDubboConfigBeans(ServiceConfig.class, configsMap); 56 | return configsMap; 57 | } 58 | 59 | private void addDubboConfigBeans(Class dubboConfigClass, Map>> configsMap) { 60 | // 获得指定类 dubboConfigClass 的 Map 61 | Map dubboConfigBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, dubboConfigClass); 62 | // 获得类的简称。例如:ApplicationConfig、ConsumerConfig 63 | String name = dubboConfigClass.getSimpleName(); 64 | // 创建 Map 65 | Map> beansMetadata = new TreeMap<>(); 66 | // 遍历 dubboConfigBeans 数组 67 | for (Map.Entry entry : dubboConfigBeans.entrySet()) { 68 | // 获得 Bean 的名字 69 | String beanName = entry.getKey(); 70 | // 获得 Bean 的元数据 71 | AbstractConfig configBean = entry.getValue(); 72 | Map configBeanMeta = super.resolveBeanMetadata(configBean); 73 | // 添加到 beansMetadata 中 74 | beansMetadata.put(beanName, configBeanMeta); 75 | } 76 | // 添加到 configsMap 中 77 | configsMap.put(name, beansMetadata); 78 | } 79 | 80 | } -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/health/DubboHealthIndicatorProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.actuate.health; 18 | 19 | import com.alibaba.dubbo.common.status.StatusChecker; 20 | 21 | import org.springframework.boot.actuate.health.HealthIndicator; 22 | import org.springframework.boot.context.properties.ConfigurationProperties; 23 | 24 | import java.util.Arrays; 25 | import java.util.LinkedHashSet; 26 | import java.util.Set; 27 | 28 | import static com.alibaba.boot.dubbo.actuate.health.DubboHealthIndicatorProperties.PREFIX; 29 | 30 | /** 31 | * Dubbo {@link HealthIndicator} Properties 32 | * 33 | * 34 | * @see HealthIndicator 35 | * @since 1.0.0 36 | */ 37 | @ConfigurationProperties(prefix = PREFIX, ignoreUnknownFields = false) // "management.health.dubbo" 开头的配置 38 | public class DubboHealthIndicatorProperties { 39 | 40 | /** 41 | * The prefix of {@link DubboHealthIndicatorProperties} 42 | */ 43 | public static final String PREFIX = "management.health.dubbo"; 44 | 45 | private Status status = new Status(); 46 | 47 | public Status getStatus() { 48 | return status; 49 | } 50 | 51 | public void setStatus(Status status) { 52 | this.status = status; 53 | } 54 | 55 | /** 56 | * The nested class for {@link StatusChecker}'s names 57 | *

 58 |      * registry=com.alibaba.dubbo.registry.status.RegistryStatusChecker
 59 |      * spring=com.alibaba.dubbo.config.spring.status.SpringStatusChecker
 60 |      * datasource=com.alibaba.dubbo.config.spring.status.DataSourceStatusChecker
 61 |      * memory=com.alibaba.dubbo.common.status.support.MemoryStatusChecker
 62 |      * load=com.alibaba.dubbo.common.status.support.LoadStatusChecker
 63 |      * server=com.alibaba.dubbo.rpc.protocol.dubbo.status.ServerStatusChecker
 64 |      * threadpool=com.alibaba.dubbo.rpc.protocol.dubbo.status.ThreadPoolStatusChecker
 65 |      * 
66 | * 67 | * @see StatusChecker 68 | */ 69 | public static class Status { 70 | 71 | /** 72 | * The defaults names of {@link StatusChecker} 73 | *

74 | * The defaults : "memory", "load" 75 | */ 76 | private Set defaults = new LinkedHashSet<>(Arrays.asList("memory", "load")); 77 | 78 | /** 79 | * The extra names of {@link StatusChecker} 80 | * 81 | * 配置的 "management.health.dubbo.extras" 集合 82 | * 83 | * 每个元素,是 StatusChecker 的实现类 84 | */ 85 | private Set extras = new LinkedHashSet<>(); 86 | 87 | public Set getDefaults() { 88 | return defaults; 89 | } 90 | 91 | public void setDefaults(Set defaults) { 92 | this.defaults = defaults; 93 | } 94 | 95 | public Set getExtras() { 96 | return extras; 97 | } 98 | 99 | public void setExtras(Set extras) { 100 | this.extras = extras; 101 | } 102 | } 103 | 104 | } -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/autoconfigure/RelaxedDubboConfigBinder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.autoconfigure; 18 | 19 | import com.alibaba.dubbo.config.AbstractConfig; 20 | import com.alibaba.dubbo.config.spring.context.properties.AbstractDubboConfigBinder; 21 | import com.alibaba.dubbo.config.spring.context.properties.DubboConfigBinder; 22 | 23 | import org.springframework.boot.context.properties.bind.BindHandler; 24 | import org.springframework.boot.context.properties.bind.Bindable; 25 | import org.springframework.boot.context.properties.bind.Binder; 26 | import org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver; 27 | import org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler; 28 | import org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler; 29 | import org.springframework.boot.context.properties.source.ConfigurationPropertySource; 30 | import org.springframework.boot.context.properties.source.UnboundElementsSourceFilter; 31 | import org.springframework.core.env.PropertySource; 32 | 33 | import static org.springframework.boot.context.properties.source.ConfigurationPropertySources.from; 34 | 35 | /** 36 | * Spring Boot Relaxed {@link DubboConfigBinder} implementation 37 | * see org.springframework.boot.context.properties.ConfigurationPropertiesBinder 38 | * 39 | * @since 0.1.1 40 | */ 41 | public class RelaxedDubboConfigBinder extends AbstractDubboConfigBinder { 42 | 43 | @Override 44 | public void bind(String prefix, C dubboConfig) { 45 | // 获得 PropertySource 数组 46 | Iterable> propertySources = getPropertySources(); 47 | // Converts ConfigurationPropertySources 48 | // 转换成 ConfigurationPropertySource 数组 49 | Iterable configurationPropertySources = from(propertySources); 50 | 51 | // Wrap Bindable from DubboConfig instance 52 | // 将 dubboConfig 包装成 Bindable 对象 53 | Bindable bindable = Bindable.ofInstance(dubboConfig); 54 | 55 | // 创建 Binder 对象 56 | Binder binder = new Binder(configurationPropertySources, new PropertySourcesPlaceholdersResolver(propertySources)); 57 | // Get BindHandler 58 | // 获得 BindHandler 对象 59 | BindHandler bindHandler = getBindHandler(); 60 | // Bind 61 | // 执行绑定,会将 propertySources 属性,注入到 dubboConfig 对象中 62 | binder.bind(prefix, bindable, bindHandler); 63 | } 64 | 65 | private BindHandler getBindHandler() { 66 | // 获得默认的 BindHandler 处理器 67 | BindHandler handler = BindHandler.DEFAULT; 68 | // 进一步包装成 IgnoreErrorsBindHandler 对象 69 | if (isIgnoreInvalidFields()) { 70 | handler = new IgnoreErrorsBindHandler(handler); 71 | } 72 | // 进一步包装成 NoUnboundElementsBindHandler 对象 73 | if (!isIgnoreUnknownFields()) { 74 | UnboundElementsSourceFilter filter = new UnboundElementsSourceFilter(); 75 | handler = new NoUnboundElementsBindHandler(handler, filter); 76 | } 77 | return handler; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/context/event/WelcomeLogoApplicationListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.context.event; 18 | 19 | import com.alibaba.dubbo.common.Version; 20 | 21 | import org.slf4j.Logger; 22 | import org.slf4j.LoggerFactory; 23 | import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; 24 | import org.springframework.boot.context.logging.LoggingApplicationListener; 25 | import org.springframework.context.ApplicationListener; 26 | import org.springframework.core.annotation.Order; 27 | 28 | import java.util.concurrent.atomic.AtomicBoolean; 29 | 30 | import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_GITHUB_URL; 31 | import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_MAILING_LIST; 32 | import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_SPRING_BOOT_GITHUB_URL; 33 | import static com.alibaba.boot.dubbo.util.DubboUtils.LINE_SEPARATOR; 34 | 35 | /** 36 | * Dubbo Welcome Logo {@link ApplicationListener} 37 | * 38 | * @see ApplicationListener 39 | * @since 1.0.0 40 | */ 41 | @Order(LoggingApplicationListener.DEFAULT_ORDER + 1) 42 | public class WelcomeLogoApplicationListener implements ApplicationListener { 43 | 44 | /** 45 | * 是否执行过 46 | * 47 | * 通过该变量,保证有且仅处理一次 ApplicationEnvironmentPreparedEvent 事件 48 | */ 49 | private static AtomicBoolean processed = new AtomicBoolean(false); 50 | 51 | @Override 52 | public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { 53 | // Skip if processed before, prevent duplicated execution in Hierarchical ApplicationContext 54 | // 如果已经处理,则直接跳过 55 | if (processed.get()) { 56 | return; 57 | } 58 | 59 | // 获得 Logger 对象 60 | /** 61 | * Gets Logger After LoggingSystem configuration ready 62 | * @see LoggingApplicationListener 63 | */ 64 | final Logger logger = LoggerFactory.getLogger(getClass()); 65 | 66 | // 获得 Dubbo Banner 文本 67 | String bannerText = buildBannerText(); 68 | if (logger.isInfoEnabled()) { 69 | logger.info(bannerText); 70 | } else { 71 | System.out.print(bannerText); 72 | } 73 | 74 | // mark processed to be true 75 | // 标记已执行 76 | processed.compareAndSet(false, true); 77 | } 78 | 79 | String buildBannerText() { 80 | StringBuilder bannerTextBuilder = new StringBuilder(); 81 | bannerTextBuilder 82 | .append(LINE_SEPARATOR) 83 | .append(LINE_SEPARATOR) 84 | .append(" :: Dubbo Spring Boot (v").append(Version.getVersion(getClass(), "1.0.0")).append(") : ") 85 | .append(DUBBO_SPRING_BOOT_GITHUB_URL) 86 | .append(LINE_SEPARATOR) 87 | .append(" :: Dubbo (v").append(Version.getVersion()).append(") : ") 88 | .append(DUBBO_GITHUB_URL) 89 | .append(LINE_SEPARATOR) 90 | .append(" :: Discuss group : ") 91 | .append(DUBBO_MAILING_LIST) 92 | .append(LINE_SEPARATOR); 93 | return bannerTextBuilder.toString(); 94 | } 95 | 96 | } -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/util/DubboUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.util; 18 | 19 | import org.junit.Assert; 20 | import org.junit.Test; 21 | import org.springframework.mock.env.MockEnvironment; 22 | 23 | import java.util.SortedMap; 24 | 25 | import static com.alibaba.boot.dubbo.util.DubboUtils.BASE_PACKAGES_PROPERTY_NAME; 26 | import static com.alibaba.boot.dubbo.util.DubboUtils.DEFAULT_MULTIPLE_CONFIG_PROPERTY_VALUE; 27 | import static com.alibaba.boot.dubbo.util.DubboUtils.DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE; 28 | import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_CONFIG_PREFIX; 29 | import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_GITHUB_URL; 30 | import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_MAILING_LIST; 31 | import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_PREFIX; 32 | import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_SCAN_PREFIX; 33 | import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_SPRING_BOOT_GITHUB_URL; 34 | import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_SPRING_BOOT_GIT_URL; 35 | import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_SPRING_BOOT_ISSUES_URL; 36 | import static com.alibaba.boot.dubbo.util.DubboUtils.MULTIPLE_CONFIG_PROPERTY_NAME; 37 | import static com.alibaba.boot.dubbo.util.DubboUtils.OVERRIDE_CONFIG_PROPERTY_NAME; 38 | import static com.alibaba.boot.dubbo.util.DubboUtils.filterDubboProperties; 39 | 40 | /** 41 | * {@link DubboUtils} Test 42 | * 43 | * 44 | * @see DubboUtils 45 | * @since 1.0.0 46 | */ 47 | public class DubboUtilsTest { 48 | 49 | @Test 50 | public void testConstants() { 51 | 52 | Assert.assertEquals("dubbo", DUBBO_PREFIX); 53 | 54 | Assert.assertEquals("dubbo.scan", DUBBO_SCAN_PREFIX); 55 | 56 | Assert.assertEquals("dubbo.scan.base-packages", BASE_PACKAGES_PROPERTY_NAME); 57 | 58 | Assert.assertEquals("dubbo.config", DUBBO_CONFIG_PREFIX); 59 | 60 | Assert.assertEquals("dubbo.config.multiple", MULTIPLE_CONFIG_PROPERTY_NAME); 61 | 62 | Assert.assertEquals("dubbo.config.override", OVERRIDE_CONFIG_PROPERTY_NAME); 63 | 64 | Assert.assertEquals("https://github.com/apache/incubator-dubbo-spring-boot-project", DUBBO_SPRING_BOOT_GITHUB_URL); 65 | Assert.assertEquals("https://github.com/apache/incubator-dubbo-spring-boot-project.git", DUBBO_SPRING_BOOT_GIT_URL); 66 | Assert.assertEquals("https://github.com/apache/incubator-dubbo-spring-boot-project/issues", DUBBO_SPRING_BOOT_ISSUES_URL); 67 | 68 | Assert.assertEquals("https://github.com/apache/incubator-dubbo", DUBBO_GITHUB_URL); 69 | 70 | Assert.assertEquals("dev@dubbo.apache.org", DUBBO_MAILING_LIST); 71 | 72 | Assert.assertFalse(DEFAULT_MULTIPLE_CONFIG_PROPERTY_VALUE); 73 | 74 | Assert.assertTrue(DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE); 75 | 76 | } 77 | 78 | 79 | @Test 80 | public void testFilterDubboProperties() { 81 | 82 | MockEnvironment environment = new MockEnvironment(); 83 | environment.setProperty("message", "Hello,World"); 84 | environment.setProperty(MULTIPLE_CONFIG_PROPERTY_NAME, "true"); 85 | environment.setProperty(OVERRIDE_CONFIG_PROPERTY_NAME, "true"); 86 | 87 | SortedMap dubboProperties = filterDubboProperties(environment); 88 | 89 | Assert.assertEquals("true",dubboProperties.get(MULTIPLE_CONFIG_PROPERTY_NAME)); 90 | Assert.assertEquals("true",dubboProperties.get(OVERRIDE_CONFIG_PROPERTY_NAME)); 91 | 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/util/EnvironmentUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.util; 18 | 19 | import org.springframework.core.env.CompositePropertySource; 20 | import org.springframework.core.env.ConfigurableEnvironment; 21 | import org.springframework.core.env.EnumerablePropertySource; 22 | import org.springframework.core.env.Environment; 23 | import org.springframework.core.env.MutablePropertySources; 24 | import org.springframework.core.env.PropertySource; 25 | import org.springframework.util.ObjectUtils; 26 | 27 | import java.util.Collections; 28 | import java.util.LinkedHashMap; 29 | import java.util.Map; 30 | 31 | /** 32 | * The utilities class for {@link Environment} 33 | * 34 | * @see Environment 35 | * @since 1.0.0 36 | */ 37 | public abstract class EnvironmentUtils { 38 | 39 | /** 40 | * Extras The properties from {@link ConfigurableEnvironment} 41 | * 42 | * @param environment {@link ConfigurableEnvironment} 43 | * @return Read-only Map 44 | */ 45 | public static Map extractProperties(ConfigurableEnvironment environment) { 46 | return Collections.unmodifiableMap(doExtraProperties(environment)); 47 | } 48 | 49 | // /** 50 | // * Gets {@link PropertySource} Map , the {@link PropertySource#getName()} as key 51 | // * 52 | // * @param environment {@link ConfigurableEnvironment} 53 | // * @return Read-only Map 54 | // */ 55 | // public static Map> getPropertySources(ConfigurableEnvironment environment) { 56 | // return Collections.unmodifiableMap(doGetPropertySources(environment)); 57 | // } 58 | 59 | private static Map doExtraProperties(ConfigurableEnvironment environment) { 60 | // 注意,是顺序的 HashMap 61 | Map properties = new LinkedHashMap<>(); // orderly 62 | // 获得所有 PropertySource 的 Map 63 | Map> map = doGetPropertySources(environment); 64 | for (PropertySource source : map.values()) { 65 | // 如果是 EnumerablePropertySource 类型 66 | if (source instanceof EnumerablePropertySource) { 67 | EnumerablePropertySource propertySource = (EnumerablePropertySource) source; 68 | // 忽略无属性值 69 | String[] propertyNames = propertySource.getPropertyNames(); 70 | if (ObjectUtils.isEmpty(propertyNames)) { 71 | continue; 72 | } 73 | // 遍历 propertyNames 数组,添加对应属性到 properties 中 74 | for (String propertyName : propertyNames) { 75 | if (!properties.containsKey(propertyName)) { // put If absent 76 | properties.put(propertyName, propertySource.getProperty(propertyName)); 77 | } 78 | } 79 | } 80 | 81 | } 82 | 83 | return properties; 84 | } 85 | 86 | private static Map> doGetPropertySources(ConfigurableEnvironment environment) { 87 | Map> map = new LinkedHashMap>(); 88 | MutablePropertySources sources = environment.getPropertySources(); 89 | // 遍历 MutablePropertySource 数组,转换成 Map 集合 90 | for (PropertySource source : sources) { 91 | extract("", map, source); 92 | } 93 | return map; 94 | } 95 | 96 | private static void extract(String root, Map> map, PropertySource source) { 97 | if (source instanceof CompositePropertySource) { 98 | for (PropertySource nest : ((CompositePropertySource) source).getPropertySources()) { 99 | extract(source.getName() + ":", map, nest); 100 | } 101 | } else { 102 | map.put(root + source.getName(), source); 103 | } 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /dubbo-spring-boot-distribution/pom.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | 21 | com.alibaba.boot 22 | dubbo-spring-boot-parent 23 | ${revision} 24 | ../dubbo-spring-boot-parent/pom.xml 25 | 26 | 4.0.0 27 | 28 | dubbo-spring-boot-distribution 29 | pom 30 | Dubbo Spring Boot Distribution 31 | Dubbo Spring Boot Distribution 32 | 33 | 34 | 35 | 36 | 37 | com.alibaba.boot 38 | dubbo-spring-boot-actuator 39 | ${revision} 40 | 41 | 42 | 43 | com.alibaba.boot 44 | dubbo-spring-boot-autoconfigure 45 | ${revision} 46 | 47 | 48 | 49 | com.alibaba.boot 50 | dubbo-spring-boot-starter 51 | ${revision} 52 | 53 | 54 | 55 | 56 | 57 | 58 | release 59 | 60 | apache-dubbo-spring-boot-project-incubating-${project.version} 61 | 62 | 63 | maven-assembly-plugin 64 | 3.1.0 65 | 66 | 67 | bin-release 68 | package 69 | 70 | single 71 | 72 | 73 | 74 | assembly/bin-release.xml 75 | 76 | 77 | 78 | 79 | source-release 80 | package 81 | 82 | single 83 | 84 | 85 | 86 | assembly/source-release.xml 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | org.apache.maven.plugins 102 | maven-deploy-plugin 103 | 2.8.2 104 | 105 | true 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/env/DubboDefaultPropertiesEnvironmentPostProcessorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.env; 18 | 19 | import org.junit.Assert; 20 | import org.junit.Test; 21 | import org.springframework.boot.SpringApplication; 22 | import org.springframework.core.Ordered; 23 | import org.springframework.core.env.MapPropertySource; 24 | import org.springframework.core.env.MutablePropertySources; 25 | import org.springframework.core.env.PropertySource; 26 | import org.springframework.mock.env.MockEnvironment; 27 | 28 | import java.util.HashMap; 29 | 30 | /** 31 | * {@link DubboDefaultPropertiesEnvironmentPostProcessor} Test 32 | */ 33 | public class DubboDefaultPropertiesEnvironmentPostProcessorTest { 34 | 35 | private DubboDefaultPropertiesEnvironmentPostProcessor instance = 36 | new DubboDefaultPropertiesEnvironmentPostProcessor(); 37 | 38 | private SpringApplication springApplication = new SpringApplication(); 39 | 40 | @Test 41 | public void testOrder() { 42 | Assert.assertEquals(Ordered.LOWEST_PRECEDENCE, instance.getOrder()); 43 | } 44 | 45 | @Test 46 | public void testPostProcessEnvironment() { 47 | MockEnvironment environment = new MockEnvironment(); 48 | // Case 1 : Not Any property 49 | instance.postProcessEnvironment(environment, springApplication); 50 | // Get PropertySources 51 | MutablePropertySources propertySources = environment.getPropertySources(); 52 | // Nothing to change 53 | PropertySource defaultPropertySource = propertySources.get("defaultProperties"); 54 | Assert.assertNotNull(defaultPropertySource); 55 | Assert.assertEquals("true", defaultPropertySource.getProperty("dubbo.config.multiple")); 56 | Assert.assertEquals("false", defaultPropertySource.getProperty("dubbo.application.qos-enable")); 57 | 58 | // Case 2 : Only set property "spring.application.name" 59 | environment.setProperty("spring.application.name", "demo-dubbo-application"); 60 | instance.postProcessEnvironment(environment, springApplication); 61 | defaultPropertySource = propertySources.get("defaultProperties"); 62 | Object dubboApplicationName = defaultPropertySource.getProperty("dubbo.application.name"); 63 | Assert.assertEquals("demo-dubbo-application", dubboApplicationName); 64 | 65 | // Case 3 : Only set property "dubbo.application.name" 66 | // Rest environment 67 | environment = new MockEnvironment(); 68 | propertySources = environment.getPropertySources(); 69 | environment.setProperty("dubbo.application.name", "demo-dubbo-application"); 70 | instance.postProcessEnvironment(environment, springApplication); 71 | defaultPropertySource = propertySources.get("defaultProperties"); 72 | Assert.assertNotNull(defaultPropertySource); 73 | dubboApplicationName = environment.getProperty("dubbo.application.name"); 74 | Assert.assertEquals("demo-dubbo-application", dubboApplicationName); 75 | 76 | // Case 4 : If "defaultProperties" PropertySource is present in PropertySources 77 | // Rest environment 78 | environment = new MockEnvironment(); 79 | propertySources = environment.getPropertySources(); 80 | propertySources.addLast(new MapPropertySource("defaultProperties", new HashMap())); 81 | environment.setProperty("spring.application.name", "demo-dubbo-application"); 82 | instance.postProcessEnvironment(environment, springApplication); 83 | defaultPropertySource = propertySources.get("defaultProperties"); 84 | dubboApplicationName = defaultPropertySource.getProperty("dubbo.application.name"); 85 | Assert.assertEquals("demo-dubbo-application", dubboApplicationName); 86 | 87 | // Case 5 : Rest dubbo.config.multiple and dubbo.application.qos-enable 88 | environment = new MockEnvironment(); 89 | propertySources = environment.getPropertySources(); 90 | propertySources.addLast(new MapPropertySource("defaultProperties", new HashMap())); 91 | environment.setProperty("dubbo.config.multiple", "false"); 92 | environment.setProperty("dubbo.application.qos-enable", "true"); 93 | instance.postProcessEnvironment(environment, springApplication); 94 | Assert.assertEquals("false", environment.getProperty("dubbo.config.multiple")); 95 | Assert.assertEquals("true", environment.getProperty("dubbo.application.qos-enable")); 96 | } 97 | } -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/AbstractDubboEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.actuate.endpoint; 18 | 19 | import com.alibaba.dubbo.config.ProtocolConfig; 20 | import com.alibaba.dubbo.config.spring.ServiceBean; 21 | import com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor; 22 | import org.springframework.beans.BeansException; 23 | import org.springframework.beans.factory.BeanFactoryUtils; 24 | import org.springframework.boot.actuate.endpoint.annotation.Endpoint; 25 | import org.springframework.context.ApplicationContext; 26 | import org.springframework.context.ApplicationContextAware; 27 | import org.springframework.context.EnvironmentAware; 28 | import org.springframework.core.env.ConfigurableEnvironment; 29 | import org.springframework.core.env.Environment; 30 | 31 | import java.beans.BeanInfo; 32 | import java.beans.Introspector; 33 | import java.beans.PropertyDescriptor; 34 | import java.lang.reflect.Method; 35 | import java.math.BigDecimal; 36 | import java.math.BigInteger; 37 | import java.net.URL; 38 | import java.util.Date; 39 | import java.util.LinkedHashMap; 40 | import java.util.Map; 41 | 42 | import static org.springframework.util.ClassUtils.isPrimitiveOrWrapper; 43 | 44 | /** 45 | * Abstract Dubbo {@link Endpoint @Endpoint} 46 | * 47 | * 48 | * @since 0.2.0 49 | */ 50 | public abstract class AbstractDubboEndpoint implements ApplicationContextAware, EnvironmentAware { 51 | 52 | protected ApplicationContext applicationContext; 53 | 54 | protected ConfigurableEnvironment environment; 55 | 56 | @Override 57 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 58 | this.applicationContext = applicationContext; 59 | } 60 | 61 | @Override 62 | public void setEnvironment(Environment environment) { 63 | if (environment instanceof ConfigurableEnvironment) { 64 | this.environment = (ConfigurableEnvironment) environment; 65 | } 66 | } 67 | 68 | /** 69 | * 解析 Bean 的元数据 70 | * 71 | * @param bean Bean 对象 72 | * @return 元数据 73 | */ 74 | protected Map resolveBeanMetadata(final Object bean) { 75 | // 创建 Map 76 | final Map beanMetadata = new LinkedHashMap<>(); 77 | try { 78 | // 获得 BeanInfo 对象 79 | BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass()); 80 | // 获得 PropertyDescriptor 数组 81 | PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); 82 | // 遍历 PropertyDescriptor 数组 83 | for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { 84 | // 获得 Method 对象 85 | Method readMethod = propertyDescriptor.getReadMethod(); 86 | // 读取属性,添加到 beanMetadata 中 87 | if (readMethod != null && isSimpleType(propertyDescriptor.getPropertyType())) { 88 | String name = Introspector.decapitalize(propertyDescriptor.getName()); 89 | Object value = readMethod.invoke(bean); 90 | beanMetadata.put(name, value); 91 | } 92 | } 93 | } catch (Exception e) { 94 | throw new RuntimeException(e); 95 | } 96 | return beanMetadata; 97 | } 98 | 99 | protected Map getServiceBeansMap() { 100 | return BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, ServiceBean.class); 101 | } 102 | 103 | protected ReferenceAnnotationBeanPostProcessor getReferenceAnnotationBeanPostProcessor() { 104 | return applicationContext.getBean(ReferenceAnnotationBeanPostProcessor.BEAN_NAME, ReferenceAnnotationBeanPostProcessor.class); 105 | } 106 | 107 | protected Map getProtocolConfigsBeanMap() { 108 | return BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, ProtocolConfig.class); 109 | } 110 | 111 | private static boolean isSimpleType(Class type) { 112 | return isPrimitiveOrWrapper(type) // 基本类型 or 包装类型 113 | || type == String.class 114 | || type == BigDecimal.class 115 | || type == BigInteger.class 116 | || type == Date.class 117 | || type == URL.class 118 | || type == Class.class 119 | ; 120 | } 121 | 122 | } -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/util/DubboUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.util; 18 | 19 | import org.springframework.core.env.ConfigurableEnvironment; 20 | 21 | import java.util.Collections; 22 | import java.util.Map; 23 | import java.util.SortedMap; 24 | import java.util.TreeMap; 25 | 26 | /** 27 | * The utilities class for Dubbo 28 | * 29 | * @since 1.0.0 30 | */ 31 | public abstract class DubboUtils { 32 | 33 | /** 34 | * line separator 35 | */ 36 | public static final String LINE_SEPARATOR = System.getProperty("line.separator"); 37 | 38 | 39 | /** 40 | * The separator of property name 41 | */ 42 | public static final String PROPERTY_NAME_SEPARATOR = "."; 43 | 44 | /** 45 | * The prefix of property name of Dubbo 46 | */ 47 | public static final String DUBBO_PREFIX = "dubbo"; 48 | 49 | /** 50 | * The prefix of property name for Dubbo scan 51 | */ 52 | public static final String DUBBO_SCAN_PREFIX = DUBBO_PREFIX + PROPERTY_NAME_SEPARATOR + "scan"; 53 | 54 | /** 55 | * The prefix of property name for Dubbo Config.ØØ 56 | */ 57 | public static final String DUBBO_CONFIG_PREFIX = DUBBO_PREFIX + PROPERTY_NAME_SEPARATOR + "config"; 58 | 59 | /** 60 | * The property name of base packages to scan 61 | *

62 | * The default value is empty set. 63 | */ 64 | public static final String BASE_PACKAGES_PROPERTY_NAME = DUBBO_SCAN_PREFIX + PROPERTY_NAME_SEPARATOR + "base-packages"; 65 | 66 | /** 67 | * The property name of multiple properties binding from externalized configuration 68 | *

69 | * The default value is {@link #DEFAULT_MULTIPLE_CONFIG_PROPERTY_VALUE} 70 | */ 71 | public static final String MULTIPLE_CONFIG_PROPERTY_NAME = DUBBO_CONFIG_PREFIX + PROPERTY_NAME_SEPARATOR + "multiple"; 72 | 73 | /** 74 | * The default value of multiple properties binding from externalized configuration 75 | */ 76 | public static final boolean DEFAULT_MULTIPLE_CONFIG_PROPERTY_VALUE = false; 77 | 78 | /** 79 | * The property name of override Dubbo config 80 | *

81 | * The default value is {@link #DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE} 82 | */ 83 | public static final String OVERRIDE_CONFIG_PROPERTY_NAME = DUBBO_CONFIG_PREFIX + PROPERTY_NAME_SEPARATOR + "override"; 84 | 85 | /** 86 | * The default property value of override Dubbo config 87 | */ 88 | public static final boolean DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE = true; 89 | 90 | 91 | /** 92 | * The github URL of Dubbo Spring Boot 93 | */ 94 | public static final String DUBBO_SPRING_BOOT_GITHUB_URL = "https://github.com/apache/incubator-dubbo-spring-boot-project"; 95 | 96 | /** 97 | * The git URL of Dubbo Spring Boot 98 | */ 99 | public static final String DUBBO_SPRING_BOOT_GIT_URL = "https://github.com/apache/incubator-dubbo-spring-boot-project.git"; 100 | 101 | /** 102 | * The issues of Dubbo Spring Boot 103 | */ 104 | public static final String DUBBO_SPRING_BOOT_ISSUES_URL = "https://github.com/apache/incubator-dubbo-spring-boot-project/issues"; 105 | 106 | /** 107 | * The github URL of Dubbo 108 | */ 109 | public static final String DUBBO_GITHUB_URL = "https://github.com/apache/incubator-dubbo"; 110 | 111 | /** 112 | * The google group URL of Dubbo 113 | */ 114 | public static final String DUBBO_MAILING_LIST = "dev@dubbo.apache.org"; 115 | 116 | /** 117 | * Filters Dubbo Properties from {@link ConfigurableEnvironment} 118 | * 119 | * @param environment {@link ConfigurableEnvironment} 120 | * @return Read-only SortedMap 121 | */ 122 | public static SortedMap filterDubboProperties(ConfigurableEnvironment environment) { 123 | SortedMap dubboProperties = new TreeMap<>(); 124 | // 获得所有的配置 125 | Map properties = EnvironmentUtils.extractProperties(environment); 126 | // 遍历配置,如果以 "dubbo." 开头,则添加到 dubboProperties 中 127 | for (Map.Entry entry : properties.entrySet()) { 128 | String propertyName = entry.getKey(); 129 | if (propertyName.startsWith(DUBBO_PREFIX + PROPERTY_NAME_SEPARATOR) 130 | && entry.getValue() != null) { 131 | dubboProperties.put(propertyName, entry.getValue().toString()); 132 | } 133 | } 134 | // 返回 dubboProperties 135 | return Collections.unmodifiableSortedMap(dubboProperties); 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | 145 | -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/autoconfigure/DubboAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.autoconfigure; 18 | 19 | import com.alibaba.dubbo.config.AbstractConfig; 20 | import com.alibaba.dubbo.config.ApplicationConfig; 21 | import com.alibaba.dubbo.config.annotation.Reference; 22 | import com.alibaba.dubbo.config.annotation.Service; 23 | import com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor; 24 | import com.alibaba.dubbo.config.spring.beans.factory.annotation.ServiceAnnotationBeanPostProcessor; 25 | import com.alibaba.dubbo.config.spring.context.annotation.DubboComponentScan; 26 | import com.alibaba.dubbo.config.spring.context.annotation.DubboConfigConfiguration; 27 | import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo; 28 | import com.alibaba.dubbo.config.spring.context.annotation.EnableDubboConfig; 29 | 30 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 31 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 32 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 33 | import org.springframework.boot.context.properties.bind.Binder; 34 | import org.springframework.boot.context.properties.source.ConfigurationPropertySources; 35 | import org.springframework.context.annotation.Bean; 36 | import org.springframework.context.annotation.Configuration; 37 | import org.springframework.context.annotation.Scope; 38 | import org.springframework.core.env.Environment; 39 | 40 | import java.util.Set; 41 | 42 | import static com.alibaba.boot.dubbo.util.DubboUtils.BASE_PACKAGES_PROPERTY_NAME; 43 | import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_PREFIX; 44 | import static com.alibaba.boot.dubbo.util.DubboUtils.MULTIPLE_CONFIG_PROPERTY_NAME; 45 | import static java.util.Collections.emptySet; 46 | import static org.springframework.beans.factory.config.ConfigurableBeanFactory.SCOPE_PROTOTYPE; 47 | 48 | /** 49 | * Dubbo Auto {@link Configuration} 50 | * 51 | * @see ApplicationConfig 52 | * @see Service 53 | * @see Reference 54 | * @see DubboComponentScan 55 | * @see EnableDubboConfig 56 | * @see EnableDubbo 57 | * @since 1.0.0 58 | */ 59 | @Configuration // 配置类 60 | @ConditionalOnProperty(prefix = DUBBO_PREFIX, name = "enabled", matchIfMissing = true, havingValue = "true") // 要求配置了 "dubbo.enabled=true" 或者,"dubbo.enabled" 未配置 61 | @ConditionalOnClass(AbstractConfig.class) // AbstractConfig 类存在的时候,即用于判断有 dubbo 库 62 | public class DubboAutoConfiguration { 63 | 64 | /** 65 | * Creates {@link ServiceAnnotationBeanPostProcessor} Bean 66 | * 67 | * @param environment {@link Environment} Bean 68 | * @return {@link ServiceAnnotationBeanPostProcessor} 69 | */ 70 | @ConditionalOnProperty(name = BASE_PACKAGES_PROPERTY_NAME) // 配置了 "dubbo.scan.base-package" 属性,即要扫描 Dubbo 注解的包 71 | @ConditionalOnClass(ConfigurationPropertySources.class) // 有 Spring Boot 配置加载的功能 72 | @Bean 73 | public ServiceAnnotationBeanPostProcessor serviceAnnotationBeanPostProcessor(Environment environment) { 74 | // 获得 "dubbo.scan.base-package" 属性 75 | Set packagesToScan = environment.getProperty(BASE_PACKAGES_PROPERTY_NAME, Set.class, emptySet()); 76 | // 创建 ServiceAnnotationBeanPostProcessor 对象 77 | return new ServiceAnnotationBeanPostProcessor(packagesToScan); 78 | } 79 | 80 | @ConditionalOnClass(Binder.class) // 存在 Binder 类的时候 81 | @Bean 82 | @Scope(scopeName = SCOPE_PROTOTYPE) // 多例 83 | public RelaxedDubboConfigBinder relaxedDubboConfigBinder() { 84 | return new RelaxedDubboConfigBinder(); 85 | } 86 | 87 | /** 88 | * Creates {@link ReferenceAnnotationBeanPostProcessor} Bean if Absent 89 | * 90 | * @return {@link ReferenceAnnotationBeanPostProcessor} 91 | */ 92 | @ConditionalOnMissingBean // 不存在 ReferenceAnnotationBeanPostProcessor Bean 的时候 93 | @Bean(name = ReferenceAnnotationBeanPostProcessor.BEAN_NAME) // Bean 的名字是 referenceAnnotationBeanPostProcessor 94 | public ReferenceAnnotationBeanPostProcessor referenceAnnotationBeanPostProcessor() { 95 | return new ReferenceAnnotationBeanPostProcessor(); 96 | } 97 | 98 | /** 99 | * Single Dubbo Config Configuration 100 | * 101 | * @see EnableDubboConfig 102 | * @see DubboConfigConfiguration.Single 103 | */ 104 | @EnableDubboConfig 105 | protected static class SingleDubboConfigConfiguration { 106 | } 107 | 108 | /** 109 | * Multiple Dubbo Config Configuration , equals @EnableDubboConfig.multiple() == true 110 | * 111 | * @see EnableDubboConfig 112 | * @see DubboConfigConfiguration.Multiple 113 | */ 114 | @ConditionalOnProperty(name = MULTIPLE_CONFIG_PROPERTY_NAME, havingValue = "true") // 要求配置 "dubbo.config.multiple=true" 。默认情况下,Dubbo 自带 "dubbo.config.multiple=true" 115 | @EnableDubboConfig(multiple = true) 116 | protected static class MultipleDubboConfigConfiguration { 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/autoconfigure/DubboAutoConfigurationOnSingleConfigTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.autoconfigure; 18 | 19 | import com.alibaba.dubbo.config.ApplicationConfig; 20 | import com.alibaba.dubbo.config.ConsumerConfig; 21 | import com.alibaba.dubbo.config.ModuleConfig; 22 | import com.alibaba.dubbo.config.MonitorConfig; 23 | import com.alibaba.dubbo.config.ProtocolConfig; 24 | import com.alibaba.dubbo.config.ProviderConfig; 25 | import com.alibaba.dubbo.config.RegistryConfig; 26 | import com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor; 27 | import com.alibaba.dubbo.config.spring.beans.factory.annotation.ServiceAnnotationBeanPostProcessor; 28 | 29 | import org.junit.Assert; 30 | import org.junit.Test; 31 | import org.junit.runner.RunWith; 32 | import org.springframework.beans.factory.annotation.Autowired; 33 | import org.springframework.boot.test.context.SpringBootTest; 34 | import org.springframework.context.ApplicationContext; 35 | import org.springframework.core.env.Environment; 36 | import org.springframework.test.context.TestPropertySource; 37 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 38 | 39 | /** 40 | * {@link DubboAutoConfiguration} Test On single Dubbo Configuration 41 | * 42 | * @since 1.0.0 43 | */ 44 | @RunWith(SpringJUnit4ClassRunner.class) 45 | @TestPropertySource( 46 | properties = { 47 | "dubbo.application.name = dubbo-demo-application", 48 | "dubbo.module.name = dubbo-demo-module", 49 | "dubbo.registry.address = zookeeper://192.168.99.100:32770", 50 | "dubbo.protocol.name=dubbo", 51 | "dubbo.protocol.port=20880", 52 | "dubbo.monitor.address=zookeeper://127.0.0.1:32770", 53 | "dubbo.provider.host=127.0.0.1", 54 | "dubbo.consumer.client=netty" 55 | } 56 | ) 57 | @SpringBootTest( 58 | classes = {DubboAutoConfiguration.class} 59 | ) 60 | public class DubboAutoConfigurationOnSingleConfigTest { 61 | 62 | @Autowired 63 | private ApplicationConfig applicationConfig; 64 | 65 | @Autowired 66 | private ModuleConfig moduleConfig; 67 | 68 | @Autowired 69 | private RegistryConfig registryConfig; 70 | 71 | @Autowired 72 | private MonitorConfig monitorConfig; 73 | 74 | @Autowired 75 | private ProviderConfig providerConfig; 76 | 77 | @Autowired 78 | private ConsumerConfig consumerConfig; 79 | 80 | @Autowired 81 | private ProtocolConfig protocolConfig; 82 | 83 | @Autowired(required = false) 84 | private DubboAutoConfiguration.MultipleDubboConfigConfiguration multipleDubboConfigConfiguration; 85 | 86 | @Autowired 87 | private DubboAutoConfiguration.SingleDubboConfigConfiguration singleDubboConfigConfiguration; 88 | 89 | @Autowired 90 | private Environment environment; 91 | 92 | @Autowired 93 | private ApplicationContext applicationContext; 94 | 95 | @Autowired(required = false) 96 | private ServiceAnnotationBeanPostProcessor serviceAnnotationBeanPostProcessor; 97 | 98 | @Autowired 99 | private ReferenceAnnotationBeanPostProcessor referenceAnnotationBeanPostProcessor; 100 | 101 | @Test 102 | public void testApplicationConfig() { 103 | 104 | Assert.assertEquals("dubbo-demo-application", applicationConfig.getName()); 105 | 106 | } 107 | 108 | @Test 109 | public void testModuleConfig() { 110 | 111 | Assert.assertEquals("dubbo-demo-module", moduleConfig.getName()); 112 | 113 | } 114 | 115 | @Test 116 | public void testRegistryConfig() { 117 | 118 | Assert.assertEquals("zookeeper://192.168.99.100:32770", registryConfig.getAddress()); 119 | 120 | } 121 | 122 | @Test 123 | public void testMonitorConfig() { 124 | 125 | Assert.assertEquals("zookeeper://127.0.0.1:32770", monitorConfig.getAddress()); 126 | 127 | } 128 | 129 | @Test 130 | public void testProtocolConfig() { 131 | 132 | Assert.assertEquals("dubbo", protocolConfig.getName()); 133 | Assert.assertEquals(Integer.valueOf(20880), protocolConfig.getPort()); 134 | 135 | } 136 | 137 | @Test 138 | public void testProviderConfig() { 139 | 140 | Assert.assertEquals("127.0.0.1", providerConfig.getHost()); 141 | 142 | } 143 | 144 | @Test 145 | public void testConsumerConfig() { 146 | 147 | Assert.assertEquals("netty", consumerConfig.getClient()); 148 | 149 | } 150 | 151 | @Test 152 | public void testMultipleDubboConfigConfiguration() { 153 | Assert.assertNotNull(multipleDubboConfigConfiguration); 154 | } 155 | 156 | @Test 157 | public void testSingleDubboConfigConfiguration() { 158 | Assert.assertNotNull(singleDubboConfigConfiguration); 159 | } 160 | 161 | @Test 162 | public void testServiceAnnotationBeanPostProcessor() { 163 | Assert.assertNotNull(multipleDubboConfigConfiguration); 164 | } 165 | 166 | } 167 | -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/context/event/AwaitingNonWebApplicationListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.context.event; 18 | 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | import org.springframework.boot.SpringApplication; 22 | import org.springframework.boot.WebApplicationType; 23 | import org.springframework.boot.context.event.ApplicationReadyEvent; 24 | import org.springframework.context.ApplicationEvent; 25 | import org.springframework.context.ApplicationListener; 26 | import org.springframework.context.event.ContextClosedEvent; 27 | import org.springframework.context.event.SmartApplicationListener; 28 | import org.springframework.util.ObjectUtils; 29 | 30 | import java.util.concurrent.ExecutorService; 31 | import java.util.concurrent.Executors; 32 | import java.util.concurrent.atomic.AtomicBoolean; 33 | import java.util.concurrent.locks.Condition; 34 | import java.util.concurrent.locks.Lock; 35 | import java.util.concurrent.locks.ReentrantLock; 36 | 37 | /** 38 | * Awaiting Non-Web Spring Boot {@link ApplicationListener} 39 | * 40 | * @since 0.1.1 41 | */ 42 | public class AwaitingNonWebApplicationListener implements SmartApplicationListener { 43 | 44 | private static final Logger logger = LoggerFactory.getLogger(AwaitingNonWebApplicationListener.class); 45 | 46 | private static final Class[] SUPPORTED_APPLICATION_EVENTS = 47 | of(ApplicationReadyEvent.class, ContextClosedEvent.class); 48 | 49 | /** 50 | * 是否已经等待完成 51 | */ 52 | private static final AtomicBoolean awaited = new AtomicBoolean(false); 53 | 54 | private final Lock lock = new ReentrantLock(); 55 | 56 | private final Condition condition = lock.newCondition(); 57 | 58 | private final ExecutorService executorService = Executors.newSingleThreadExecutor(); 59 | 60 | @Override 61 | public boolean supportsEventType(Class eventType) { 62 | return ObjectUtils.containsElement(SUPPORTED_APPLICATION_EVENTS, eventType); 63 | } 64 | 65 | @Override 66 | public boolean supportsSourceType(Class sourceType) { 67 | return true; 68 | } 69 | 70 | private static T[] of(T... values) { 71 | return values; 72 | } 73 | 74 | @Override 75 | public void onApplicationEvent(ApplicationEvent event) { 76 | if (event instanceof ApplicationReadyEvent) { 77 | onApplicationReadyEvent((ApplicationReadyEvent) event); 78 | } else if (event instanceof ContextClosedEvent) { 79 | onContextClosedEvent((ContextClosedEvent) event); 80 | } 81 | } 82 | 83 | @Override 84 | public int getOrder() { 85 | return LOWEST_PRECEDENCE; 86 | } 87 | 88 | protected void onApplicationReadyEvent(ApplicationReadyEvent event) { 89 | // 如果是 Web 环境,则直接返回 90 | final SpringApplication springApplication = event.getSpringApplication(); 91 | if (!WebApplicationType.NONE.equals(springApplication.getWebApplicationType())) { 92 | return; 93 | } 94 | // 启动一个用户线程,从而实现等待 95 | await(); 96 | } 97 | 98 | protected void onContextClosedEvent(ContextClosedEvent event) { 99 | // 释放 100 | release(); 101 | // 关闭线程池 102 | shutdown(); 103 | } 104 | 105 | protected void await() { 106 | // has been waited, return immediately 107 | // 如果已经处于阻塞等待,直接返回 108 | if (awaited.get()) { 109 | return; 110 | } 111 | 112 | // 创建任务,实现阻塞 113 | executorService.execute(() -> executeMutually(() -> { 114 | while (!awaited.get()) { 115 | if (logger.isInfoEnabled()) { 116 | logger.info(" [Dubbo] Current Spring Boot Application is await..."); 117 | } 118 | try { 119 | condition.await(); 120 | System.out.println("123"); 121 | } catch (InterruptedException e) { 122 | Thread.currentThread().interrupt(); 123 | } 124 | } 125 | })); 126 | } 127 | 128 | protected void release() { 129 | executeMutually(() -> { 130 | // CAS 设置 awaited 为 true 131 | while (awaited.compareAndSet(false, true)) { 132 | if (logger.isInfoEnabled()) { 133 | logger.info(" [Dubbo] Current Spring Boot Application is about to shutdown..."); 134 | } 135 | // 通知 Condition 136 | condition.signalAll(); 137 | } 138 | }); 139 | } 140 | 141 | private void shutdown() { 142 | if (!executorService.isShutdown()) { 143 | // Shutdown executorService 144 | executorService.shutdown(); 145 | } 146 | } 147 | 148 | private void executeMutually(Runnable runnable) { 149 | try { 150 | lock.lock(); 151 | // 执行 Runnable 152 | runnable.run(); 153 | } finally { 154 | lock.unlock(); 155 | } 156 | } 157 | 158 | static AtomicBoolean getAwaited() { 159 | return awaited; 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 17 | 19 | 4.0.0 20 | 21 | 22 | org.sonatype.oss 23 | oss-parent 24 | 7 25 | 26 | 27 | com.alibaba.boot 28 | dubbo-spring-boot-project 29 | ${revision} 30 | 31 | pom 32 | 33 | Dubbo Spring Boot Project 34 | Dubbo Spring Boot Project 35 | https://github.com/apache/incubator-dubbo-spring-boot-project 36 | 37 | 38 | 3.0.1 39 | 2.19.1 40 | 0.2.1 41 | 42 | 43 | 44 | dubbo-spring-boot-parent 45 | dubbo-spring-boot-distribution 46 | dubbo-spring-boot-autoconfigure 47 | dubbo-spring-boot-starter 48 | dubbo-spring-boot-samples 49 | dubbo-spring-boot-actuator 50 | 51 | 52 | 53 | The Apache Software Foundation 54 | http://www.apache.org/ 55 | 56 | 57 | 58 | https://github.com/apache/incubator-dubbo-spring-boot-project 59 | scm:git:git:////github.com/apache/incubator-dubbo-spring-boot-project.git 60 | scm:git:ssh://git@//github.com/apache/incubator-dubbo-spring-boot-project.git 61 | 62 | 63 | 64 | 65 | Github 66 | https://github.com/apache/incubator-dubbo-spring-boot-project/issues 67 | 68 | 69 | 70 | 71 | Development List 72 | dev-subscribe@dubbo.apache.org 73 | dev-unsubscribe@dubbo.apache.org 74 | dev@dubbo.apache.org 75 | 76 | 77 | Commits List 78 | commits-subscribe@dubbo.apache.org 79 | commits-unsubscribe@dubbo.apache.org 80 | commits@dubbo.apache.org 81 | 82 | 83 | Issues List 84 | issues-subscribe@dubbo.apache.org 85 | issues-unsubscribe@dubbo.apache.org 86 | issues@dubbo.apache.org 87 | 88 | 89 | 90 | 91 | Apache Dubbo (incubating) 92 | The Apache Dubbo (incubating) Project Contributors 93 | dev@dubbo.apache.org 94 | http://dubbo.apache.org 95 | 96 | 97 | 98 | 99 | 100 | release 101 | 102 | 103 | 104 | org.apache.maven.plugins 105 | maven-javadoc-plugin 106 | 107 | 108 | package 109 | 110 | jar 111 | 112 | 113 | 114 | 115 | 116 | 117 | org.apache.maven.plugins 118 | maven-gpg-plugin 119 | 120 | 121 | verify 122 | 123 | sign 124 | 125 | 126 | 127 | 128 | 129 | 130 | org.codehaus.mojo 131 | flatten-maven-plugin 132 | 1.1.0 133 | 134 | true 135 | resolveCiFriendliesOnly 136 | 137 | 138 | 139 | flatten 140 | process-resources 141 | 142 | flatten 143 | 144 | 145 | 146 | flatten.clean 147 | clean 148 | 149 | clean 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/env/DubboDefaultPropertiesEnvironmentPostProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.boot.dubbo.env; 18 | 19 | import com.alibaba.dubbo.config.ApplicationConfig; 20 | import com.alibaba.dubbo.config.spring.context.annotation.EnableDubboConfig; 21 | import com.alibaba.dubbo.config.spring.context.annotation.EnableDubboConfigBinding; 22 | 23 | import org.springframework.boot.SpringApplication; 24 | import org.springframework.boot.context.ContextIdApplicationContextInitializer; 25 | import org.springframework.boot.env.EnvironmentPostProcessor; 26 | import org.springframework.context.ConfigurableApplicationContext; 27 | import org.springframework.core.Ordered; 28 | import org.springframework.core.env.ConfigurableEnvironment; 29 | import org.springframework.core.env.Environment; 30 | import org.springframework.core.env.MapPropertySource; 31 | import org.springframework.core.env.MutablePropertySources; 32 | import org.springframework.core.env.PropertySource; 33 | import org.springframework.util.CollectionUtils; 34 | import org.springframework.util.StringUtils; 35 | 36 | import java.util.HashMap; 37 | import java.util.Map; 38 | import java.util.Properties; 39 | 40 | /** 41 | * The lowest precedence {@link EnvironmentPostProcessor} processes 42 | * {@link SpringApplication#setDefaultProperties(Properties) Spring Boot default properties} for Dubbo 43 | * as late as possible before {@link ConfigurableApplicationContext#refresh() application context refresh}. 44 | */ 45 | public class DubboDefaultPropertiesEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered { 46 | 47 | /** 48 | * The name of default {@link PropertySource} defined in SpringApplication#configurePropertySources method. 49 | */ 50 | private static final String PROPERTY_SOURCE_NAME = "defaultProperties"; 51 | 52 | /** 53 | * The property name of Spring Application 54 | * 55 | * @see ContextIdApplicationContextInitializer 56 | */ 57 | private static final String SPRING_APPLICATION_NAME_PROPERTY = "spring.application.name"; 58 | 59 | /** 60 | * The property name of {@link ApplicationConfig} 61 | * 62 | * @see EnableDubboConfig 63 | * @see EnableDubboConfigBinding 64 | */ 65 | private static final String DUBBO_APPLICATION_NAME_PROPERTY = "dubbo.application.name"; 66 | 67 | /** 68 | * The property name of {@link EnableDubboConfig#multiple() @EnableDubboConfig.multiple()} 69 | */ 70 | private static final String DUBBO_CONFIG_MULTIPLE_PROPERTY = "dubbo.config.multiple"; 71 | 72 | /** 73 | * The property name of {@link ApplicationConfig#getQosEnable() application's QOS enable} 74 | */ 75 | private static final String DUBBO_APPLICATION_QOS_ENABLE_PROPERTY = "dubbo.application.qos-enable"; 76 | 77 | @Override 78 | public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { 79 | MutablePropertySources propertySources = environment.getPropertySources(); 80 | // 生成 Dubbo 默认配置 81 | Map defaultProperties = createDefaultProperties(environment); 82 | // 有默认配置,则添加到 environment 中 83 | if (!CollectionUtils.isEmpty(defaultProperties)) { 84 | addOrReplace(propertySources, defaultProperties); 85 | } 86 | } 87 | 88 | @Override 89 | public int getOrder() { 90 | return LOWEST_PRECEDENCE; 91 | } 92 | 93 | private Map createDefaultProperties(ConfigurableEnvironment environment) { 94 | Map defaultProperties = new HashMap(); 95 | // "dubbo.application.name" 96 | setDubboApplicationNameProperty(environment, defaultProperties); 97 | // "dubbo.config.multiple" 98 | setDubboConfigMultipleProperty(defaultProperties); 99 | // "dubbo.application.qos-enable" 100 | setDubboApplicationQosEnableProperty(defaultProperties); 101 | return defaultProperties; 102 | } 103 | 104 | private void setDubboApplicationNameProperty(Environment environment, Map defaultProperties) { 105 | String springApplicationName = environment.getProperty(SPRING_APPLICATION_NAME_PROPERTY); 106 | if (StringUtils.hasLength(springApplicationName) 107 | && !environment.containsProperty(DUBBO_APPLICATION_NAME_PROPERTY)) { 108 | defaultProperties.put(DUBBO_APPLICATION_NAME_PROPERTY, springApplicationName); 109 | } 110 | } 111 | 112 | private void setDubboConfigMultipleProperty(Map defaultProperties) { 113 | defaultProperties.put(DUBBO_CONFIG_MULTIPLE_PROPERTY, Boolean.TRUE.toString()); 114 | } 115 | 116 | private void setDubboApplicationQosEnableProperty(Map defaultProperties) { 117 | defaultProperties.put(DUBBO_APPLICATION_QOS_ENABLE_PROPERTY, Boolean.FALSE.toString()); 118 | } 119 | 120 | /** 121 | * Copy from BusEnvironmentPostProcessor#addOrReplace(MutablePropertySources, Map) 122 | * 123 | * @param propertySources {@link MutablePropertySources} 124 | * @param map Default Dubbo Properties 125 | */ 126 | private void addOrReplace(MutablePropertySources propertySources, Map map) { 127 | // 情况一,获得到 "defaultProperties" 对应的 PropertySource 对象,则进行替换 128 | MapPropertySource target = null; 129 | if (propertySources.contains(PROPERTY_SOURCE_NAME)) { 130 | PropertySource source = propertySources.get(PROPERTY_SOURCE_NAME); 131 | if (source instanceof MapPropertySource) { // 找到 132 | target = (MapPropertySource) source; 133 | // 遍历 map 数组,进行替换到 "defaultProperties" 中 134 | for (String key : map.keySet()) { 135 | if (!target.containsProperty(key)) { 136 | target.getSource().put(key, map.get(key)); 137 | } 138 | } 139 | } 140 | } 141 | // 情况二,不存在 "defaultProperties" 对应的 PropertySource 对象,则进行添加 142 | if (target == null) { 143 | target = new MapPropertySource(PROPERTY_SOURCE_NAME, map); 144 | } 145 | if (!propertySources.contains(PROPERTY_SOURCE_NAME)) { 146 | propertySources.addLast(target); 147 | } 148 | } 149 | 150 | } -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | if [ "$MVNW_VERBOSE" = true ]; then 205 | echo $MAVEN_PROJECTBASEDIR 206 | fi 207 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 208 | 209 | # For Cygwin, switch paths to Windows format before running java 210 | if $cygwin; then 211 | [ -n "$M2_HOME" ] && 212 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 213 | [ -n "$JAVA_HOME" ] && 214 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 215 | [ -n "$CLASSPATH" ] && 216 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 217 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 218 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 219 | fi 220 | 221 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 222 | 223 | exec "$JAVACMD" \ 224 | $MAVEN_OPTS \ 225 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 226 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 227 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 228 | 229 | --------------------------------------------------------------------------------