├── .gitignore ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── .travis.yml ├── LICENSE ├── NOTICE ├── README.md ├── README_CN.md ├── dubbo-spring-boot-actuator ├── JMX_HealthEndpoint.png ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── dubbo │ │ │ └── spring │ │ │ └── boot │ │ │ └── actuate │ │ │ ├── autoconfigure │ │ │ └── DubboEndpointAnnotationAutoConfiguration.java │ │ │ └── endpoint │ │ │ ├── DubboConfigsMetadataEndpoint.java │ │ │ ├── DubboMetadataEndpoint.java │ │ │ ├── DubboPropertiesMetadataEndpoint.java │ │ │ ├── DubboReferencesMetadataEndpoint.java │ │ │ ├── DubboServicesMetadataEndpoint.java │ │ │ └── DubboShutdownEndpoint.java │ └── resources │ │ └── META-INF │ │ ├── dubbo-endpoints-default.properties │ │ └── spring.factories │ └── test │ └── java │ └── org │ └── apache │ └── dubbo │ └── spring │ └── boot │ └── actuate │ ├── autoconfigure │ └── DubboEndpointAnnotationAutoConfigurationTest.java │ └── endpoint │ └── DubboEndpointTest.java ├── dubbo-spring-boot-autoconfigure ├── README.md ├── config-popup-window.png ├── mconfig-popup-window.png ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── dubbo │ │ │ └── spring │ │ │ └── boot │ │ │ └── autoconfigure │ │ │ ├── BinderDubboConfigBinder.java │ │ │ ├── DelegatingPropertyResolver.java │ │ │ └── DubboRelaxedBinding2AutoConfiguration.java │ └── resources │ │ └── META-INF │ │ └── spring.factories │ └── test │ ├── java │ └── org │ │ └── apache │ │ └── dubbo │ │ └── spring │ │ └── boot │ │ ├── autoconfigure │ │ ├── BinderDubboConfigBinderTest.java │ │ └── DubboRelaxedBinding2AutoConfigurationTest.java │ │ ├── context │ │ └── event │ │ │ └── AwaitingNonWebApplicationListenerTest.java │ │ ├── env │ │ └── DubboDefaultPropertiesEnvironmentPostProcessorTest.java │ │ └── util │ │ └── EnvironmentUtilsTest.java │ └── resources │ └── dubbo.properties ├── dubbo-spring-boot-compatible ├── actuator │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── org │ │ │ │ └── apache │ │ │ │ └── dubbo │ │ │ │ └── spring │ │ │ │ └── boot │ │ │ │ └── actuate │ │ │ │ ├── autoconfigure │ │ │ │ ├── DubboEndpointAutoConfiguration.java │ │ │ │ ├── DubboEndpointMetadataAutoConfiguration.java │ │ │ │ ├── DubboHealthIndicatorAutoConfiguration.java │ │ │ │ └── DubboMvcEndpointManagementContextConfiguration.java │ │ │ │ ├── endpoint │ │ │ │ ├── DubboEndpoint.java │ │ │ │ ├── metadata │ │ │ │ │ ├── AbstractDubboMetadata.java │ │ │ │ │ ├── DubboConfigsMetadata.java │ │ │ │ │ ├── DubboMetadata.java │ │ │ │ │ ├── DubboPropertiesMetadata.java │ │ │ │ │ ├── DubboReferencesMetadata.java │ │ │ │ │ ├── DubboServicesMetadata.java │ │ │ │ │ └── DubboShutdownMetadata.java │ │ │ │ └── mvc │ │ │ │ │ └── DubboMvcEndpoint.java │ │ │ │ └── health │ │ │ │ ├── DubboHealthIndicator.java │ │ │ │ └── DubboHealthIndicatorProperties.java │ │ └── resources │ │ │ └── META-INF │ │ │ └── spring.factories │ │ └── test │ │ └── java │ │ └── org │ │ └── apache │ │ └── dubbo │ │ └── spring │ │ └── boot │ │ └── actuate │ │ ├── autoconfigure │ │ └── DubboEndpointAutoConfigurationTest.java │ │ └── health │ │ └── DubboHealthIndicatorTest.java ├── autoconfigure │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── org │ │ │ │ └── apache │ │ │ │ └── dubbo │ │ │ │ └── spring │ │ │ │ └── boot │ │ │ │ ├── autoconfigure │ │ │ │ ├── DubboAutoConfiguration.java │ │ │ │ ├── DubboConfigurationProperties.java │ │ │ │ ├── DubboRelaxedBindingAutoConfiguration.java │ │ │ │ └── RelaxedDubboConfigBinder.java │ │ │ │ ├── beans │ │ │ │ └── factory │ │ │ │ │ └── config │ │ │ │ │ ├── DubboConfigBeanCustomizer.java │ │ │ │ │ ├── DubboConfigBeanDefinitionConflictProcessor.java │ │ │ │ │ └── OverrideBeanDefinitionRegistryPostProcessor.java │ │ │ │ ├── context │ │ │ │ ├── DubboApplicationContextInitializer.java │ │ │ │ └── event │ │ │ │ │ ├── AwaitingNonWebApplicationListener.java │ │ │ │ │ ├── DubboConfigBeanDefinitionConflictApplicationListener.java │ │ │ │ │ ├── OverrideDubboConfigApplicationListener.java │ │ │ │ │ └── WelcomeLogoApplicationListener.java │ │ │ │ ├── env │ │ │ │ └── DubboDefaultPropertiesEnvironmentPostProcessor.java │ │ │ │ └── util │ │ │ │ ├── DubboUtils.java │ │ │ │ └── EnvironmentUtils.java │ │ └── resources │ │ │ └── META-INF │ │ │ └── spring.factories │ │ └── test │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── dubbo │ │ │ └── spring │ │ │ └── boot │ │ │ ├── autoconfigure │ │ │ ├── CompatibleDubboAutoConfigurationTest.java │ │ │ ├── CompatibleDubboAutoConfigurationTestWithoutProperties.java │ │ │ ├── DubboAutoConfigurationOnMultipleConfigTest.java │ │ │ ├── DubboAutoConfigurationOnSingleConfigTest.java │ │ │ └── RelaxedDubboConfigBinderTest.java │ │ │ ├── beans │ │ │ └── factory │ │ │ │ └── config │ │ │ │ └── DubboConfigBeanDefinitionConflictProcessorTest.java │ │ │ ├── context │ │ │ └── event │ │ │ │ ├── AwaitingNonWebApplicationListenerTest.java │ │ │ │ ├── DubboConfigBeanDefinitionConflictApplicationListenerTest.java │ │ │ │ ├── OverrideDubboConfigApplicationListenerDisableTest.java │ │ │ │ ├── OverrideDubboConfigApplicationListenerTest.java │ │ │ │ └── WelcomeLogoApplicationListenerTest.java │ │ │ ├── env │ │ │ └── DubboDefaultPropertiesEnvironmentPostProcessorTest.java │ │ │ └── util │ │ │ ├── DubboUtilsTest.java │ │ │ └── EnvironmentUtilsTest.java │ │ └── resources │ │ └── META-INF │ │ ├── dubbo.properties │ │ └── spring │ │ └── dubbo-context.xml └── pom.xml ├── dubbo-spring-boot-distribution ├── assembly │ ├── bin-release.xml │ └── source-release.xml └── pom.xml ├── dubbo-spring-boot-parent └── pom.xml ├── dubbo-spring-boot-samples ├── auto-configure-samples │ ├── consumer-sample │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── org │ │ │ │ └── apache │ │ │ │ └── dubbo │ │ │ │ └── spring │ │ │ │ └── boot │ │ │ │ └── demo │ │ │ │ └── consumer │ │ │ │ └── bootstrap │ │ │ │ └── DubboAutoConfigurationConsumerBootstrap.java │ │ │ └── resources │ │ │ └── application.yml │ ├── pom.xml │ └── provider-sample │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── dubbo │ │ │ └── spring │ │ │ └── boot │ │ │ └── demo │ │ │ └── provider │ │ │ ├── bootstrap │ │ │ └── DubboAutoConfigurationProviderBootstrap.java │ │ │ └── service │ │ │ └── DefaultDemoService.java │ │ └── resources │ │ └── application.properties ├── dubbo-registry-nacos-samples │ ├── consumer-sample │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── org │ │ │ │ └── apache │ │ │ │ └── dubbo │ │ │ │ └── spring │ │ │ │ └── boot │ │ │ │ └── demo │ │ │ │ └── consumer │ │ │ │ └── bootstrap │ │ │ │ └── DubboRegistryNacosConsumerBootstrap.java │ │ │ └── resources │ │ │ └── application.yml │ ├── pom.xml │ └── provider-sample │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── dubbo │ │ │ └── spring │ │ │ └── boot │ │ │ └── demo │ │ │ └── provider │ │ │ ├── bootstrap │ │ │ └── DubboRegistryNacosProviderBootstrap.java │ │ │ └── service │ │ │ └── DefaultDemoService.java │ │ └── resources │ │ └── application.properties ├── dubbo-registry-zookeeper-samples │ ├── consumer-sample │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── org │ │ │ │ └── apache │ │ │ │ └── dubbo │ │ │ │ └── spring │ │ │ │ └── boot │ │ │ │ └── demo │ │ │ │ └── consumer │ │ │ │ └── bootstrap │ │ │ │ └── DubboRegistryZooKeeperConsumerBootstrap.java │ │ │ └── resources │ │ │ └── application.yml │ ├── pom.xml │ └── provider-sample │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── dubbo │ │ │ └── spring │ │ │ └── boot │ │ │ └── demo │ │ │ └── provider │ │ │ ├── bootstrap │ │ │ ├── DubboRegistryZooKeeperProviderBootstrap.java │ │ │ └── EmbeddedZooKeeper.java │ │ │ └── service │ │ │ └── DefaultDemoService.java │ │ └── resources │ │ └── application.properties ├── externalized-configuration-samples │ ├── consumer-sample │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── org │ │ │ │ └── apache │ │ │ │ └── dubbo │ │ │ │ └── spring │ │ │ │ └── boot │ │ │ │ └── demo │ │ │ │ └── consumer │ │ │ │ └── bootstrap │ │ │ │ └── DubboExternalizedConfigurationConsumerBootstrap.java │ │ │ └── resources │ │ │ └── application.yml │ ├── pom.xml │ └── provider-sample │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── dubbo │ │ │ └── spring │ │ │ └── boot │ │ │ └── demo │ │ │ └── provider │ │ │ ├── bootstrap │ │ │ └── DubboExternalizedConfigurationProviderBootstrap.java │ │ │ └── service │ │ │ └── DefaultDemoService.java │ │ └── resources │ │ └── application.properties ├── pom.xml └── sample-api │ ├── pom.xml │ └── src │ └── main │ └── java │ └── org │ └── apache │ └── dubbo │ └── spring │ └── boot │ └── demo │ └── consumer │ └── DemoService.java ├── dubbo-spring-boot-starter └── pom.xml ├── mvnw ├── mvnw.cmd └── pom.xml /.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 | .factorypath 28 | 29 | # idea ignore 30 | .idea/ 31 | *.ipr 32 | *.iml 33 | *.iws 34 | target 35 | 36 | # temp ignore 37 | *.log 38 | *.cache 39 | *.diff 40 | *.patch 41 | *.tmp 42 | 43 | # system ignore 44 | .DS_Store 45 | Thumbs.db 46 | 47 | # Maven ignore 48 | .flattened-pom.xml 49 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mercyblitz/dubbo-spring-boot-project/c9b8d80fed96da5a9ea1c732e9a653924aac1574/.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 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | sudo: false # faster builds 3 | 4 | jdk: 5 | - openjdk11 6 | - openjdk8 7 | 8 | script: "mvn clean package" 9 | 10 | after_success: 11 | - bash <(curl -s https://codecov.io/bash) 12 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Apache Dubbo 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/). -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/JMX_HealthEndpoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mercyblitz/dubbo-spring-boot-project/c9b8d80fed96da5a9ea1c732e9a653924aac1574/dubbo-spring-boot-actuator/JMX_HealthEndpoint.png -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | org.apache.dubbo 23 | dubbo-spring-boot-parent 24 | ${revision} 25 | ../dubbo-spring-boot-parent/pom.xml 26 | 27 | 4.0.0 28 | 29 | dubbo-spring-boot-actuator 30 | jar 31 | Apache Dubbo Spring Boot :: Actuator 32 | Apache Dubbo Spring Boot Actuator 33 | 34 | 35 | 36 | 37 | org.apache.dubbo 38 | dubbo-spring-boot-actuator-compatible 39 | ${revision} 40 | 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-web 46 | true 47 | 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-starter-actuator 52 | true 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-autoconfigure 58 | true 59 | 60 | 61 | 62 | 63 | org.apache.dubbo 64 | dubbo-spring-boot-autoconfigure 65 | ${revision} 66 | 67 | 68 | 69 | 70 | org.springframework.boot 71 | spring-boot-starter-test 72 | test 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboEndpointAnnotationAutoConfiguration.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 org.apache.dubbo.spring.boot.actuate.autoconfigure; 18 | 19 | import org.apache.dubbo.spring.boot.actuate.endpoint.DubboConfigsMetadataEndpoint; 20 | import org.apache.dubbo.spring.boot.actuate.endpoint.DubboMetadataEndpoint; 21 | import org.apache.dubbo.spring.boot.actuate.endpoint.DubboPropertiesMetadataEndpoint; 22 | import org.apache.dubbo.spring.boot.actuate.endpoint.DubboReferencesMetadataEndpoint; 23 | import org.apache.dubbo.spring.boot.actuate.endpoint.DubboServicesMetadataEndpoint; 24 | import org.apache.dubbo.spring.boot.actuate.endpoint.DubboShutdownEndpoint; 25 | import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint; 26 | import org.springframework.boot.actuate.endpoint.annotation.Endpoint; 27 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 28 | import org.springframework.context.annotation.Bean; 29 | import org.springframework.context.annotation.Configuration; 30 | import org.springframework.context.annotation.PropertySource; 31 | 32 | /** 33 | * Dubbo {@link Endpoint @Endpoint} Auto-{@link Configuration} for Spring Boot Actuator 2.0 34 | * 35 | * @see Endpoint 36 | * @see Configuration 37 | * @since 2.7.0 38 | */ 39 | @Configuration 40 | @PropertySource( 41 | name = "Dubbo Endpoints Default Properties", 42 | value = "classpath:/META-INF/dubbo-endpoints-default.properties") 43 | public class DubboEndpointAnnotationAutoConfiguration { 44 | 45 | @Bean 46 | @ConditionalOnMissingBean 47 | @ConditionalOnEnabledEndpoint 48 | public DubboMetadataEndpoint dubboEndpoint() { 49 | return new DubboMetadataEndpoint(); 50 | } 51 | 52 | @Bean 53 | @ConditionalOnMissingBean 54 | @ConditionalOnEnabledEndpoint 55 | public DubboConfigsMetadataEndpoint dubboConfigsMetadataEndpoint() { 56 | return new DubboConfigsMetadataEndpoint(); 57 | } 58 | 59 | @Bean 60 | @ConditionalOnMissingBean 61 | @ConditionalOnEnabledEndpoint 62 | public DubboPropertiesMetadataEndpoint dubboPropertiesEndpoint() { 63 | return new DubboPropertiesMetadataEndpoint(); 64 | } 65 | 66 | @Bean 67 | @ConditionalOnMissingBean 68 | @ConditionalOnEnabledEndpoint 69 | public DubboReferencesMetadataEndpoint dubboReferencesMetadataEndpoint() { 70 | return new DubboReferencesMetadataEndpoint(); 71 | } 72 | 73 | @Bean 74 | @ConditionalOnMissingBean 75 | @ConditionalOnEnabledEndpoint 76 | public DubboServicesMetadataEndpoint dubboServicesMetadataEndpoint() { 77 | return new DubboServicesMetadataEndpoint(); 78 | } 79 | 80 | @Bean 81 | @ConditionalOnMissingBean 82 | @ConditionalOnEnabledEndpoint 83 | public DubboShutdownEndpoint dubboShutdownEndpoint() { 84 | return new DubboShutdownEndpoint(); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.actuate.endpoint; 18 | 19 | import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.AbstractDubboMetadata; 20 | import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.DubboConfigsMetadata; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.boot.actuate.endpoint.annotation.Endpoint; 23 | import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; 24 | 25 | import java.util.Map; 26 | 27 | /** 28 | * Dubbo Configs Metadata {@link Endpoint} 29 | * 30 | * @since 2.7.0 31 | */ 32 | @Endpoint(id = "dubboconfigs") 33 | public class DubboConfigsMetadataEndpoint extends AbstractDubboMetadata { 34 | 35 | @Autowired 36 | private DubboConfigsMetadata dubboConfigsMetadata; 37 | 38 | @ReadOperation 39 | public Map>> configs() { 40 | return dubboConfigsMetadata.configs(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboMetadataEndpoint.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 org.apache.dubbo.spring.boot.actuate.endpoint; 18 | 19 | import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.DubboMetadata; 20 | import org.springframework.beans.factory.annotation.Autowired; 21 | import org.springframework.boot.actuate.endpoint.annotation.Endpoint; 22 | import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; 23 | 24 | import java.util.Map; 25 | 26 | /** 27 | * Actuator {@link Endpoint} to expose Dubbo Meta Data 28 | * 29 | * @see Endpoint 30 | * @since 2.7.0 31 | */ 32 | @Endpoint(id = "dubbo") 33 | public class DubboMetadataEndpoint { 34 | 35 | @Autowired 36 | private DubboMetadata dubboMetadata; 37 | 38 | @ReadOperation 39 | public Map invoke() { 40 | return dubboMetadata.invoke(); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboPropertiesMetadataEndpoint.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 org.apache.dubbo.spring.boot.actuate.endpoint; 18 | 19 | import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.AbstractDubboMetadata; 20 | import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.DubboPropertiesMetadata; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.boot.actuate.endpoint.annotation.Endpoint; 23 | import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; 24 | 25 | import java.util.SortedMap; 26 | 27 | /** 28 | * Dubbo Properties {@link Endpoint} 29 | * 30 | * @since 2.7.0 31 | */ 32 | @Endpoint(id = "dubboproperties") 33 | public class DubboPropertiesMetadataEndpoint extends AbstractDubboMetadata { 34 | 35 | @Autowired 36 | private DubboPropertiesMetadata dubboPropertiesMetadata; 37 | 38 | @ReadOperation 39 | public SortedMap properties() { 40 | return dubboPropertiesMetadata.properties(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.actuate.endpoint; 18 | 19 | import org.apache.dubbo.config.annotation.Reference; 20 | import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.AbstractDubboMetadata; 21 | import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.DubboReferencesMetadata; 22 | import org.springframework.beans.factory.annotation.Autowired; 23 | import org.springframework.boot.actuate.endpoint.annotation.Endpoint; 24 | import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; 25 | 26 | import java.util.Map; 27 | 28 | /** 29 | * Dubbo {@link Reference} Metadata {@link Endpoint} 30 | * 31 | * @since 2.7.0 32 | */ 33 | @Endpoint(id = "dubboreferences") 34 | public class DubboReferencesMetadataEndpoint extends AbstractDubboMetadata { 35 | 36 | @Autowired 37 | private DubboReferencesMetadata dubboReferencesMetadata; 38 | 39 | @ReadOperation 40 | public Map> references() { 41 | return dubboReferencesMetadata.references(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.actuate.endpoint; 18 | 19 | import org.apache.dubbo.config.annotation.Service; 20 | import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.AbstractDubboMetadata; 21 | import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.DubboServicesMetadata; 22 | import org.springframework.beans.factory.annotation.Autowired; 23 | import org.springframework.boot.actuate.endpoint.annotation.Endpoint; 24 | import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; 25 | 26 | import java.util.Map; 27 | 28 | /** 29 | * Dubbo {@link Service} Metadata {@link Endpoint} 30 | * 31 | * @since 2.7.0 32 | */ 33 | @Endpoint(id = "dubboservices") 34 | public class DubboServicesMetadataEndpoint extends AbstractDubboMetadata { 35 | 36 | @Autowired 37 | private DubboServicesMetadata dubboServicesMetadata; 38 | 39 | @ReadOperation 40 | public Map> services() { 41 | return dubboServicesMetadata.services(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.actuate.endpoint; 18 | 19 | import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.AbstractDubboMetadata; 20 | import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.DubboShutdownMetadata; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.boot.actuate.endpoint.annotation.Endpoint; 23 | import org.springframework.boot.actuate.endpoint.annotation.WriteOperation; 24 | 25 | import java.util.Map; 26 | 27 | /** 28 | * Dubbo Shutdown 29 | * 30 | * @since 2.7.0 31 | */ 32 | @Endpoint(id = "dubboshutdown") 33 | public class DubboShutdownEndpoint extends AbstractDubboMetadata { 34 | 35 | @Autowired 36 | private DubboShutdownMetadata dubboShutdownMetadata; 37 | 38 | @WriteOperation 39 | public Map shutdown() throws Exception { 40 | return dubboShutdownMetadata.shutdown(); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/main/resources/META-INF/dubbo-endpoints-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 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 16 | 17 | management.endpoints.web.path-mapping.dubboshutdown = dubbo/shutdown 18 | management.endpoints.web.path-mapping.dubboconfigs = dubbo/configs 19 | management.endpoints.web.path-mapping.dubboservices = dubbo/services 20 | management.endpoints.web.path-mapping.dubboreferences = dubbo/references 21 | management.endpoints.web.path-mapping.dubboproperties = dubbo/properties -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | org.apache.dubbo.spring.boot.actuate.autoconfigure.DubboEndpointAnnotationAutoConfiguration -------------------------------------------------------------------------------- /dubbo-spring-boot-actuator/src/test/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.actuate.endpoint; 18 | 19 | import org.apache.dubbo.spring.boot.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.autoconfigure.EnableAutoConfiguration; 26 | import org.springframework.boot.test.context.SpringBootTest; 27 | import org.springframework.test.context.junit4.SpringRunner; 28 | 29 | import java.util.Map; 30 | 31 | import static org.apache.dubbo.common.Version.getVersion; 32 | 33 | /** 34 | * {@link DubboMetadataEndpoint} Test 35 | * 36 | * @see DubboMetadataEndpoint 37 | * @since 2.7.0 38 | */ 39 | @RunWith(SpringRunner.class) 40 | @SpringBootTest( 41 | classes = { 42 | DubboMetadataEndpoint.class 43 | } 44 | ) 45 | @EnableAutoConfiguration 46 | public class DubboEndpointTest { 47 | 48 | 49 | @Autowired 50 | private DubboMetadataEndpoint dubboEndpoint; 51 | 52 | @Test 53 | public void testInvoke() { 54 | 55 | Map metadata = dubboEndpoint.invoke(); 56 | 57 | Assert.assertNotNull(metadata.get("timestamp")); 58 | 59 | Map versions = (Map) metadata.get("versions"); 60 | Map urls = (Map) metadata.get("urls"); 61 | 62 | Assert.assertFalse(versions.isEmpty()); 63 | Assert.assertFalse(urls.isEmpty()); 64 | 65 | Assert.assertEquals(getVersion(DubboUtils.class, "1.0.0"), versions.get("dubbo-spring-boot")); 66 | Assert.assertEquals(getVersion(), versions.get("dubbo")); 67 | 68 | Assert.assertEquals("https://github.com/apache/dubbo", urls.get("dubbo")); 69 | Assert.assertEquals("dev@dubbo.apache.org", urls.get("mailing-list")); 70 | Assert.assertEquals("https://github.com/apache/dubbo-spring-boot-project", urls.get("github")); 71 | Assert.assertEquals("https://github.com/apache/dubbo-spring-boot-project/issues", urls.get("issues")); 72 | Assert.assertEquals("https://github.com/apache/dubbo-spring-boot-project.git", urls.get("git")); 73 | 74 | } 75 | 76 | 77 | } 78 | -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/config-popup-window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mercyblitz/dubbo-spring-boot-project/c9b8d80fed96da5a9ea1c732e9a653924aac1574/dubbo-spring-boot-autoconfigure/config-popup-window.png -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/mconfig-popup-window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mercyblitz/dubbo-spring-boot-project/c9b8d80fed96da5a9ea1c732e9a653924aac1574/dubbo-spring-boot-autoconfigure/mconfig-popup-window.png -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | org.apache.dubbo 23 | dubbo-spring-boot-parent 24 | ${revision} 25 | ../dubbo-spring-boot-parent/pom.xml 26 | 27 | 4.0.0 28 | 29 | dubbo-spring-boot-autoconfigure 30 | jar 31 | Apache Dubbo Spring Boot :: Auto-Configure 32 | Apache Dubbo Spring Boot Auto-Configure 33 | 34 | 35 | 36 | 37 | 38 | 39 | org.apache.dubbo 40 | dubbo-spring-boot-autoconfigure-compatible 41 | ${revision} 42 | 43 | 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-autoconfigure 48 | true 49 | 50 | 51 | 52 | org.springframework.boot 53 | spring-boot-starter-logging 54 | true 55 | 56 | 57 | 58 | 59 | org.apache.dubbo 60 | dubbo 61 | 62 | 63 | 64 | 65 | org.springframework.boot 66 | spring-boot-starter-test 67 | test 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/BinderDubboConfigBinder.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 org.apache.dubbo.spring.boot.autoconfigure; 18 | 19 | import org.apache.dubbo.config.spring.context.properties.DubboConfigBinder; 20 | 21 | import com.alibaba.spring.context.config.ConfigurationBeanBinder; 22 | import org.springframework.boot.context.properties.bind.BindHandler; 23 | import org.springframework.boot.context.properties.bind.Bindable; 24 | import org.springframework.boot.context.properties.bind.Binder; 25 | import org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver; 26 | import org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler; 27 | import org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler; 28 | import org.springframework.boot.context.properties.source.ConfigurationPropertySource; 29 | import org.springframework.boot.context.properties.source.UnboundElementsSourceFilter; 30 | import org.springframework.core.env.MapPropertySource; 31 | import org.springframework.core.env.PropertySource; 32 | 33 | import java.util.Map; 34 | 35 | import static java.util.Arrays.asList; 36 | import static org.springframework.boot.context.properties.source.ConfigurationPropertySources.from; 37 | 38 | /** 39 | * Spring Boot Relaxed {@link DubboConfigBinder} implementation 40 | * see org.springframework.boot.context.properties.ConfigurationPropertiesBinder 41 | * 42 | * @since 2.7.0 43 | */ 44 | class BinderDubboConfigBinder implements ConfigurationBeanBinder { 45 | 46 | @Override 47 | public void bind(Map configurationProperties, boolean ignoreUnknownFields, 48 | boolean ignoreInvalidFields, Object configurationBean) { 49 | 50 | Iterable> propertySources = asList(new MapPropertySource("internal", configurationProperties)); 51 | 52 | // Converts ConfigurationPropertySources 53 | Iterable configurationPropertySources = from(propertySources); 54 | 55 | // Wrap Bindable from DubboConfig instance 56 | Bindable bindable = Bindable.ofInstance(configurationBean); 57 | 58 | Binder binder = new Binder(configurationPropertySources, new PropertySourcesPlaceholdersResolver(propertySources)); 59 | 60 | // Get BindHandler 61 | BindHandler bindHandler = getBindHandler(ignoreUnknownFields, ignoreInvalidFields); 62 | 63 | // Bind 64 | binder.bind("", bindable, bindHandler); 65 | } 66 | 67 | private BindHandler getBindHandler(boolean ignoreUnknownFields, 68 | boolean ignoreInvalidFields) { 69 | BindHandler handler = BindHandler.DEFAULT; 70 | if (ignoreInvalidFields) { 71 | handler = new IgnoreErrorsBindHandler(handler); 72 | } 73 | if (!ignoreUnknownFields) { 74 | UnboundElementsSourceFilter filter = new UnboundElementsSourceFilter(); 75 | handler = new NoUnboundElementsBindHandler(handler, filter); 76 | } 77 | return handler; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/DelegatingPropertyResolver.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 org.apache.dubbo.spring.boot.autoconfigure; 18 | 19 | import org.apache.dubbo.common.utils.Assert; 20 | import org.springframework.core.env.PropertyResolver; 21 | import org.springframework.lang.Nullable; 22 | 23 | /** 24 | * Delegating {@link PropertyResolver} 25 | * 26 | * @since 2.7.1 27 | */ 28 | class DelegatingPropertyResolver implements PropertyResolver { 29 | 30 | private final PropertyResolver delegate; 31 | 32 | DelegatingPropertyResolver(PropertyResolver delegate) { 33 | Assert.notNull(delegate, "The delegate of PropertyResolver must not be null"); 34 | this.delegate = delegate; 35 | } 36 | 37 | @Override 38 | public boolean containsProperty(String key) { 39 | return delegate.containsProperty(key); 40 | } 41 | 42 | @Override 43 | @Nullable 44 | public String getProperty(String key) { 45 | return delegate.getProperty(key); 46 | } 47 | 48 | @Override 49 | public String getProperty(String key, String defaultValue) { 50 | return delegate.getProperty(key, defaultValue); 51 | } 52 | 53 | @Override 54 | @Nullable 55 | public T getProperty(String key, Class targetType) { 56 | return delegate.getProperty(key, targetType); 57 | } 58 | 59 | @Override 60 | public T getProperty(String key, Class targetType, T defaultValue) { 61 | return delegate.getProperty(key, targetType, defaultValue); 62 | } 63 | 64 | @Override 65 | public String getRequiredProperty(String key) throws IllegalStateException { 66 | return delegate.getRequiredProperty(key); 67 | } 68 | 69 | @Override 70 | public T getRequiredProperty(String key, Class targetType) throws IllegalStateException { 71 | return delegate.getRequiredProperty(key, targetType); 72 | } 73 | 74 | @Override 75 | public String resolvePlaceholders(String text) { 76 | return delegate.resolvePlaceholders(text); 77 | } 78 | 79 | @Override 80 | public String resolveRequiredPlaceholders(String text) throws IllegalArgumentException { 81 | return delegate.resolveRequiredPlaceholders(text); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/DubboRelaxedBinding2AutoConfiguration.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 org.apache.dubbo.spring.boot.autoconfigure; 18 | 19 | import com.alibaba.spring.context.config.ConfigurationBeanBinder; 20 | import org.springframework.boot.autoconfigure.AutoConfigureBefore; 21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 22 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 23 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 24 | import org.springframework.boot.context.properties.source.ConfigurationPropertySources; 25 | import org.springframework.context.annotation.Bean; 26 | import org.springframework.context.annotation.Configuration; 27 | import org.springframework.context.annotation.Scope; 28 | import org.springframework.core.env.AbstractEnvironment; 29 | import org.springframework.core.env.ConfigurableEnvironment; 30 | import org.springframework.core.env.MapPropertySource; 31 | import org.springframework.core.env.MutablePropertySources; 32 | import org.springframework.core.env.PropertyResolver; 33 | 34 | import java.util.Map; 35 | 36 | import static com.alibaba.spring.util.PropertySourcesUtils.getSubProperties; 37 | import static org.apache.dubbo.spring.boot.util.DubboUtils.BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME; 38 | import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_PREFIX; 39 | import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_SCAN_PREFIX; 40 | import static org.apache.dubbo.spring.boot.util.DubboUtils.RELAXED_DUBBO_CONFIG_BINDER_BEAN_NAME; 41 | import static org.springframework.beans.factory.config.ConfigurableBeanFactory.SCOPE_PROTOTYPE; 42 | 43 | /** 44 | * Dubbo Relaxed Binding Auto-{@link Configuration} for Spring Boot 2.0 45 | * 46 | * @see DubboRelaxedBindingAutoConfiguration 47 | * @since 2.7.0 48 | */ 49 | @Configuration 50 | @ConditionalOnProperty(prefix = DUBBO_PREFIX, name = "enabled", matchIfMissing = true) 51 | @ConditionalOnClass(name = "org.springframework.boot.context.properties.bind.Binder") 52 | @AutoConfigureBefore(DubboRelaxedBindingAutoConfiguration.class) 53 | public class DubboRelaxedBinding2AutoConfiguration { 54 | 55 | @Bean(name = BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME) 56 | public PropertyResolver dubboScanBasePackagesPropertyResolver(ConfigurableEnvironment environment) { 57 | ConfigurableEnvironment propertyResolver = new AbstractEnvironment() { 58 | @Override 59 | protected void customizePropertySources(MutablePropertySources propertySources) { 60 | Map dubboScanProperties = getSubProperties(environment.getPropertySources(), DUBBO_SCAN_PREFIX); 61 | propertySources.addLast(new MapPropertySource("dubboScanProperties", dubboScanProperties)); 62 | } 63 | }; 64 | ConfigurationPropertySources.attach(propertyResolver); 65 | return new DelegatingPropertyResolver(propertyResolver); 66 | } 67 | 68 | @ConditionalOnMissingBean(name = RELAXED_DUBBO_CONFIG_BINDER_BEAN_NAME, value = ConfigurationBeanBinder.class) 69 | @Bean(RELAXED_DUBBO_CONFIG_BINDER_BEAN_NAME) 70 | @Scope(scopeName = SCOPE_PROTOTYPE) 71 | public ConfigurationBeanBinder relaxedDubboConfigBinder() { 72 | return new BinderDubboConfigBinder(); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | org.apache.dubbo.spring.boot.autoconfigure.DubboRelaxedBinding2AutoConfiguration -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/test/java/org/apache/dubbo/spring/boot/autoconfigure/BinderDubboConfigBinderTest.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 org.apache.dubbo.spring.boot.autoconfigure; 18 | 19 | import org.apache.dubbo.config.ApplicationConfig; 20 | import org.apache.dubbo.config.ProtocolConfig; 21 | import org.apache.dubbo.config.RegistryConfig; 22 | 23 | import com.alibaba.spring.context.config.ConfigurationBeanBinder; 24 | import org.junit.Assert; 25 | import org.junit.Test; 26 | import org.junit.runner.RunWith; 27 | import org.springframework.beans.factory.annotation.Autowired; 28 | import org.springframework.core.env.ConfigurableEnvironment; 29 | import org.springframework.test.context.ContextConfiguration; 30 | import org.springframework.test.context.TestPropertySource; 31 | import org.springframework.test.context.junit4.SpringRunner; 32 | 33 | import java.util.Map; 34 | 35 | import static com.alibaba.spring.util.PropertySourcesUtils.getSubProperties; 36 | 37 | /** 38 | * {@link BinderDubboConfigBinder} Test 39 | * 40 | * @since 2.7.0 41 | */ 42 | @RunWith(SpringRunner.class) 43 | @TestPropertySource(locations = "classpath:/dubbo.properties") 44 | @ContextConfiguration(classes = BinderDubboConfigBinder.class) 45 | public class BinderDubboConfigBinderTest { 46 | 47 | @Autowired 48 | private ConfigurationBeanBinder dubboConfigBinder; 49 | 50 | @Autowired 51 | private ConfigurableEnvironment environment; 52 | 53 | @Test 54 | public void testBinder() { 55 | 56 | ApplicationConfig applicationConfig = new ApplicationConfig(); 57 | Map properties = getSubProperties(environment.getPropertySources(), "dubbo.application"); 58 | dubboConfigBinder.bind(properties, true, true, applicationConfig); 59 | Assert.assertEquals("hello", applicationConfig.getName()); 60 | Assert.assertEquals("world", applicationConfig.getOwner()); 61 | 62 | RegistryConfig registryConfig = new RegistryConfig(); 63 | properties = getSubProperties(environment.getPropertySources(), "dubbo.registry"); 64 | dubboConfigBinder.bind(properties, true, true, registryConfig); 65 | Assert.assertEquals("10.20.153.17", registryConfig.getAddress()); 66 | 67 | ProtocolConfig protocolConfig = new ProtocolConfig(); 68 | properties = getSubProperties(environment.getPropertySources(), "dubbo.protocol"); 69 | dubboConfigBinder.bind(properties, true, true, protocolConfig); 70 | Assert.assertEquals(Integer.valueOf(20881), protocolConfig.getPort()); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /dubbo-spring-boot-autoconfigure/src/test/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.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-autoconfigure/src/test/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.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 | * @see EnvironmentUtils 33 | * @since 2.7.0 34 | */ 35 | public class EnvironmentUtilsTest { 36 | 37 | @Test 38 | public void testExtraProperties() { 39 | 40 | System.setProperty("user.name", "mercyblitz"); 41 | 42 | StandardEnvironment environment = new StandardEnvironment(); 43 | 44 | Map map = new HashMap<>(); 45 | 46 | map.put("user.name", "Mercy"); 47 | 48 | MapPropertySource propertySource = new MapPropertySource("first", map); 49 | 50 | CompositePropertySource compositePropertySource = new CompositePropertySource("comp"); 51 | 52 | compositePropertySource.addFirstPropertySource(propertySource); 53 | 54 | MutablePropertySources propertySources = environment.getPropertySources(); 55 | 56 | propertySources.addFirst(compositePropertySource); 57 | 58 | Map properties = EnvironmentUtils.extractProperties(environment); 59 | 60 | Assert.assertEquals("Mercy", properties.get("user.name")); 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /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-compatible/actuator/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | org.apache.dubbo 23 | dubbo-spring-boot-compatible 24 | ${revision} 25 | ../pom.xml 26 | 27 | 4.0.0 28 | 29 | dubbo-spring-boot-actuator-compatible 30 | Apache Dubbo Spring Boot :: Compatible :: Actuator 31 | Apache Dubbo Spring Boot Compatible for Spring Boot 1.x 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 | org.apache.dubbo 63 | dubbo-spring-boot-autoconfigure-compatible 64 | ${revision} 65 | 66 | 67 | 68 | 69 | org.springframework.boot 70 | spring-boot-starter-test 71 | test 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboEndpointAutoConfiguration.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 org.apache.dubbo.spring.boot.actuate.autoconfigure; 18 | 19 | 20 | import org.apache.dubbo.spring.boot.actuate.endpoint.DubboEndpoint; 21 | import org.apache.dubbo.spring.boot.autoconfigure.DubboAutoConfiguration; 22 | import org.apache.dubbo.spring.boot.autoconfigure.DubboRelaxedBindingAutoConfiguration; 23 | 24 | import org.springframework.boot.actuate.condition.ConditionalOnEnabledEndpoint; 25 | import org.springframework.boot.actuate.endpoint.Endpoint; 26 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 27 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 28 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 29 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 30 | import org.springframework.context.annotation.Bean; 31 | import org.springframework.context.annotation.Configuration; 32 | 33 | /** 34 | * Dubbo {@link Endpoint} Auto Configuration is compatible with Spring Boot Actuator 1.x 35 | * 36 | * @since 2.7.0 37 | */ 38 | @Configuration 39 | @ConditionalOnClass(name = { 40 | "org.springframework.boot.actuate.endpoint.Endpoint" // Spring Boot 1.x 41 | }) 42 | @AutoConfigureAfter(value = { 43 | DubboAutoConfiguration.class, 44 | DubboRelaxedBindingAutoConfiguration.class 45 | }) 46 | @EnableConfigurationProperties(DubboEndpoint.class) 47 | public class DubboEndpointAutoConfiguration { 48 | 49 | @Bean 50 | @ConditionalOnMissingBean 51 | @ConditionalOnEnabledEndpoint(value = "dubbo") 52 | public DubboEndpoint dubboEndpoint() { 53 | return new DubboEndpoint(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboEndpointMetadataAutoConfiguration.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 org.apache.dubbo.spring.boot.actuate.autoconfigure; 18 | 19 | import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.AbstractDubboMetadata; 20 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 22 | import org.springframework.context.annotation.ComponentScan; 23 | import org.springframework.context.annotation.Configuration; 24 | 25 | /** 26 | * Dubbo Endpoints Metadata Auto-{@link Configuration} 27 | */ 28 | @ConditionalOnClass(name = { 29 | "org.springframework.boot.actuate.health.Health" // If spring-boot-actuator is present 30 | }) 31 | @Configuration 32 | @AutoConfigureAfter(name = { 33 | "org.apache.dubbo.spring.boot.autoconfigure.DubboAutoConfiguration", 34 | "org.apache.dubbo.spring.boot.autoconfigure.DubboRelaxedBindingAutoConfiguration" 35 | }) 36 | @ComponentScan(basePackageClasses = AbstractDubboMetadata.class) 37 | public class DubboEndpointMetadataAutoConfiguration { 38 | } 39 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/actuator/src/main/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.actuate.autoconfigure; 18 | 19 | import org.apache.dubbo.spring.boot.actuate.health.DubboHealthIndicator; 20 | import org.apache.dubbo.spring.boot.actuate.health.DubboHealthIndicatorProperties; 21 | import org.springframework.boot.actuate.health.HealthIndicator; 22 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 23 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 24 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 25 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 26 | import org.springframework.context.annotation.Bean; 27 | import org.springframework.context.annotation.Configuration; 28 | 29 | /** 30 | * Dubbo {@link DubboHealthIndicator} Auto Configuration 31 | * 32 | * @see HealthIndicator 33 | * @since 2.7.0 34 | */ 35 | @Configuration 36 | @ConditionalOnClass(name = { 37 | "org.springframework.boot.actuate.health.Health" 38 | }) 39 | @ConditionalOnProperty(name = "management.health.dubbo.enabled", matchIfMissing = true, havingValue = "true") 40 | @EnableConfigurationProperties(DubboHealthIndicatorProperties.class) 41 | public class DubboHealthIndicatorAutoConfiguration { 42 | 43 | @Bean 44 | @ConditionalOnMissingBean 45 | public DubboHealthIndicator dubboHealthIndicator() { 46 | return new DubboHealthIndicator(); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboMvcEndpointManagementContextConfiguration.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 org.apache.dubbo.spring.boot.actuate.autoconfigure; 18 | 19 | 20 | import org.apache.dubbo.spring.boot.actuate.endpoint.DubboEndpoint; 21 | import org.apache.dubbo.spring.boot.actuate.endpoint.mvc.DubboMvcEndpoint; 22 | import org.springframework.boot.actuate.autoconfigure.ManagementContextConfiguration; 23 | import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint; 24 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 25 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 26 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 27 | import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; 28 | import org.springframework.context.annotation.Bean; 29 | 30 | /** 31 | * Dubbo {@link MvcEndpoint} {@link ManagementContextConfiguration} for Spring Boot 1.x 32 | * 33 | * @since 2.7.0 34 | */ 35 | @ManagementContextConfiguration 36 | @ConditionalOnClass(name = { 37 | "org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter" 38 | }) 39 | @ConditionalOnWebApplication 40 | public class DubboMvcEndpointManagementContextConfiguration { 41 | 42 | @Bean 43 | @ConditionalOnBean(DubboEndpoint.class) 44 | @ConditionalOnMissingBean 45 | public DubboMvcEndpoint dubboMvcEndpoint(DubboEndpoint dubboEndpoint) { 46 | return new DubboMvcEndpoint(dubboEndpoint); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/actuator/src/main/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.actuate.endpoint; 18 | 19 | 20 | import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.DubboMetadata; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.boot.actuate.endpoint.AbstractEndpoint; 23 | import org.springframework.boot.actuate.endpoint.Endpoint; 24 | import org.springframework.boot.context.properties.ConfigurationProperties; 25 | 26 | import java.util.Map; 27 | 28 | /** 29 | * Actuator {@link Endpoint} to expose Dubbo Meta Data 30 | * 31 | * @see Endpoint 32 | * @since 2.7.0 33 | */ 34 | @ConfigurationProperties(prefix = "endpoints.dubbo", ignoreUnknownFields = false) 35 | public class DubboEndpoint extends AbstractEndpoint> { 36 | 37 | @Autowired 38 | private DubboMetadata dubboMetadata; 39 | 40 | public DubboEndpoint() { 41 | super("dubbo", true, false); 42 | } 43 | 44 | @Override 45 | public Map invoke() { 46 | return dubboMetadata.invoke(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboConfigsMetadata.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 org.apache.dubbo.spring.boot.actuate.endpoint.metadata; 18 | 19 | import org.apache.dubbo.config.AbstractConfig; 20 | import org.apache.dubbo.config.ApplicationConfig; 21 | import org.apache.dubbo.config.ConsumerConfig; 22 | import org.apache.dubbo.config.MethodConfig; 23 | import org.apache.dubbo.config.ModuleConfig; 24 | import org.apache.dubbo.config.MonitorConfig; 25 | import org.apache.dubbo.config.ProtocolConfig; 26 | import org.apache.dubbo.config.ProviderConfig; 27 | import org.apache.dubbo.config.ReferenceConfig; 28 | import org.apache.dubbo.config.RegistryConfig; 29 | import org.apache.dubbo.config.ServiceConfig; 30 | import org.springframework.stereotype.Component; 31 | 32 | import java.util.LinkedHashMap; 33 | import java.util.Map; 34 | import java.util.TreeMap; 35 | 36 | import static org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors; 37 | 38 | /** 39 | * Dubbo Configs Metadata 40 | * 41 | * @since 2.7.0 42 | */ 43 | @Component 44 | public class DubboConfigsMetadata extends AbstractDubboMetadata { 45 | 46 | public Map>> configs() { 47 | 48 | Map>> configsMap = new LinkedHashMap<>(); 49 | 50 | addDubboConfigBeans(ApplicationConfig.class, configsMap); 51 | addDubboConfigBeans(ConsumerConfig.class, configsMap); 52 | addDubboConfigBeans(MethodConfig.class, configsMap); 53 | addDubboConfigBeans(ModuleConfig.class, configsMap); 54 | addDubboConfigBeans(MonitorConfig.class, configsMap); 55 | addDubboConfigBeans(ProtocolConfig.class, configsMap); 56 | addDubboConfigBeans(ProviderConfig.class, configsMap); 57 | addDubboConfigBeans(ReferenceConfig.class, configsMap); 58 | addDubboConfigBeans(RegistryConfig.class, configsMap); 59 | addDubboConfigBeans(ServiceConfig.class, configsMap); 60 | 61 | return configsMap; 62 | 63 | } 64 | 65 | private void addDubboConfigBeans(Class dubboConfigClass, 66 | Map>> configsMap) { 67 | 68 | Map dubboConfigBeans = beansOfTypeIncludingAncestors(applicationContext, dubboConfigClass); 69 | 70 | String name = dubboConfigClass.getSimpleName(); 71 | 72 | Map> beansMetadata = new TreeMap<>(); 73 | 74 | for (Map.Entry entry : dubboConfigBeans.entrySet()) { 75 | 76 | String beanName = entry.getKey(); 77 | AbstractConfig configBean = entry.getValue(); 78 | Map configBeanMeta = resolveBeanMetadata(configBean); 79 | beansMetadata.put(beanName, configBeanMeta); 80 | 81 | } 82 | 83 | configsMap.put(name, beansMetadata); 84 | 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboMetadata.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 org.apache.dubbo.spring.boot.actuate.endpoint.metadata; 18 | 19 | import org.apache.dubbo.common.Version; 20 | import org.apache.dubbo.spring.boot.util.DubboUtils; 21 | import org.springframework.stereotype.Component; 22 | 23 | import java.util.LinkedHashMap; 24 | import java.util.Map; 25 | 26 | import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_GITHUB_URL; 27 | import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_MAILING_LIST; 28 | import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_SPRING_BOOT_GITHUB_URL; 29 | import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_SPRING_BOOT_GIT_URL; 30 | import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_SPRING_BOOT_ISSUES_URL; 31 | 32 | /** 33 | * Dubbo Metadata 34 | * @since 2.7.0 35 | */ 36 | @Component 37 | public class DubboMetadata { 38 | 39 | public Map invoke() { 40 | 41 | Map metaData = new LinkedHashMap<>(); 42 | 43 | metaData.put("timestamp", System.currentTimeMillis()); 44 | 45 | Map versions = new LinkedHashMap<>(); 46 | versions.put("dubbo-spring-boot", Version.getVersion(DubboUtils.class, "1.0.0")); 47 | versions.put("dubbo", Version.getVersion()); 48 | 49 | Map urls = new LinkedHashMap<>(); 50 | urls.put("dubbo", DUBBO_GITHUB_URL); 51 | urls.put("mailing-list", DUBBO_MAILING_LIST); 52 | urls.put("github", DUBBO_SPRING_BOOT_GITHUB_URL); 53 | urls.put("issues", DUBBO_SPRING_BOOT_ISSUES_URL); 54 | urls.put("git", DUBBO_SPRING_BOOT_GIT_URL); 55 | 56 | metaData.put("versions", versions); 57 | metaData.put("urls", urls); 58 | 59 | return metaData; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboPropertiesMetadata.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 org.apache.dubbo.spring.boot.actuate.endpoint.metadata; 18 | 19 | import org.springframework.stereotype.Component; 20 | 21 | import java.util.SortedMap; 22 | 23 | import static org.apache.dubbo.spring.boot.util.DubboUtils.filterDubboProperties; 24 | 25 | /** 26 | * Dubbo Properties Metadata 27 | * 28 | * @since 2.7.0 29 | */ 30 | @Component 31 | public class DubboPropertiesMetadata extends AbstractDubboMetadata { 32 | 33 | public SortedMap properties() { 34 | return filterDubboProperties(environment); 35 | } 36 | } -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboReferencesMetadata.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 org.apache.dubbo.spring.boot.actuate.endpoint.metadata; 18 | 19 | import org.apache.dubbo.config.annotation.Reference; 20 | import org.apache.dubbo.config.spring.ReferenceBean; 21 | import org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor; 22 | import org.springframework.beans.factory.annotation.InjectionMetadata; 23 | import org.springframework.stereotype.Component; 24 | 25 | import java.util.LinkedHashMap; 26 | import java.util.Map; 27 | 28 | /** 29 | * Dubbo {@link Reference} Metadata 30 | * 31 | * @since 2.7.0 32 | */ 33 | @Component 34 | public class DubboReferencesMetadata extends AbstractDubboMetadata { 35 | 36 | public Map> references() { 37 | 38 | Map> referencesMetadata = new LinkedHashMap<>(); 39 | 40 | ReferenceAnnotationBeanPostProcessor beanPostProcessor = getReferenceAnnotationBeanPostProcessor(); 41 | 42 | referencesMetadata.putAll(buildReferencesMetadata(beanPostProcessor.getInjectedFieldReferenceBeanMap())); 43 | referencesMetadata.putAll(buildReferencesMetadata(beanPostProcessor.getInjectedMethodReferenceBeanMap())); 44 | 45 | return referencesMetadata; 46 | 47 | } 48 | 49 | private Map> buildReferencesMetadata( 50 | Map> injectedElementReferenceBeanMap) { 51 | Map> referencesMetadata = new LinkedHashMap<>(); 52 | 53 | for (Map.Entry> entry : 54 | injectedElementReferenceBeanMap.entrySet()) { 55 | 56 | InjectionMetadata.InjectedElement injectedElement = entry.getKey(); 57 | 58 | ReferenceBean referenceBean = entry.getValue(); 59 | 60 | Map beanMetadata = resolveBeanMetadata(referenceBean); 61 | beanMetadata.put("invoker", resolveBeanMetadata(referenceBean.get())); 62 | 63 | referencesMetadata.put(String.valueOf(injectedElement.getMember()), beanMetadata); 64 | 65 | } 66 | 67 | return referencesMetadata; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboServicesMetadata.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 org.apache.dubbo.spring.boot.actuate.endpoint.metadata; 18 | 19 | import org.apache.dubbo.config.annotation.Service; 20 | import org.apache.dubbo.config.spring.ServiceBean; 21 | import org.springframework.stereotype.Component; 22 | 23 | import java.util.LinkedHashMap; 24 | import java.util.Map; 25 | 26 | /** 27 | * Dubbo {@link Service} Metadata 28 | * 29 | * @since 2.7.0 30 | */ 31 | @Component 32 | public class DubboServicesMetadata extends AbstractDubboMetadata { 33 | 34 | public Map> services() { 35 | 36 | Map serviceBeansMap = getServiceBeansMap(); 37 | 38 | Map> servicesMetadata = new LinkedHashMap<>(serviceBeansMap.size()); 39 | 40 | for (Map.Entry entry : serviceBeansMap.entrySet()) { 41 | 42 | String serviceBeanName = entry.getKey(); 43 | 44 | ServiceBean serviceBean = entry.getValue(); 45 | 46 | Map serviceBeanMetadata = resolveBeanMetadata(serviceBean); 47 | 48 | Object service = resolveServiceBean(serviceBeanName, serviceBean); 49 | 50 | if (service != null) { 51 | // Add Service implementation class 52 | serviceBeanMetadata.put("serviceClass", service.getClass().getName()); 53 | } 54 | 55 | servicesMetadata.put(serviceBeanName, serviceBeanMetadata); 56 | 57 | } 58 | 59 | return servicesMetadata; 60 | 61 | } 62 | 63 | private Object resolveServiceBean(String serviceBeanName, ServiceBean serviceBean) { 64 | 65 | int index = serviceBeanName.indexOf("#"); 66 | 67 | if (index > -1) { 68 | 69 | Class interfaceClass = serviceBean.getInterfaceClass(); 70 | 71 | String serviceName = serviceBeanName.substring(index + 1); 72 | 73 | if (applicationContext.containsBean(serviceName)) { 74 | return applicationContext.getBean(serviceName, interfaceClass); 75 | } 76 | 77 | } 78 | 79 | return null; 80 | 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboShutdownMetadata.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 org.apache.dubbo.spring.boot.actuate.endpoint.metadata; 18 | 19 | import org.apache.dubbo.config.spring.ServiceBean; 20 | import org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor; 21 | import org.springframework.stereotype.Component; 22 | 23 | import java.util.LinkedHashMap; 24 | import java.util.Map; 25 | import java.util.TreeMap; 26 | 27 | import static org.apache.dubbo.registry.support.AbstractRegistryFactory.getRegistries; 28 | 29 | /** 30 | * Dubbo Shutdown 31 | * 32 | * @since 2.7.0 33 | */ 34 | @Component 35 | public class DubboShutdownMetadata extends AbstractDubboMetadata { 36 | 37 | 38 | public Map shutdown() throws Exception { 39 | 40 | Map shutdownCountData = new LinkedHashMap<>(); 41 | 42 | // registries 43 | int registriesCount = getRegistries().size(); 44 | 45 | // protocols 46 | int protocolsCount = getProtocolConfigsBeanMap().size(); 47 | 48 | shutdownCountData.put("registries", registriesCount); 49 | shutdownCountData.put("protocols", protocolsCount); 50 | 51 | // Service Beans 52 | Map serviceBeansMap = getServiceBeansMap(); 53 | if (!serviceBeansMap.isEmpty()) { 54 | for (ServiceBean serviceBean : serviceBeansMap.values()) { 55 | serviceBean.destroy(); 56 | } 57 | } 58 | shutdownCountData.put("services", serviceBeansMap.size()); 59 | 60 | // Reference Beans 61 | ReferenceAnnotationBeanPostProcessor beanPostProcessor = getReferenceAnnotationBeanPostProcessor(); 62 | 63 | int referencesCount = beanPostProcessor.getReferenceBeans().size(); 64 | 65 | beanPostProcessor.destroy(); 66 | 67 | shutdownCountData.put("references", referencesCount); 68 | 69 | // Set Result to complete 70 | Map shutdownData = new TreeMap<>(); 71 | shutdownData.put("shutdown.count", shutdownCountData); 72 | 73 | 74 | return shutdownData; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/actuator/src/main/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.actuate.health; 18 | 19 | import org.apache.dubbo.common.status.StatusChecker; 20 | import org.springframework.boot.actuate.health.HealthIndicator; 21 | import org.springframework.boot.context.properties.ConfigurationProperties; 22 | 23 | import java.util.Arrays; 24 | import java.util.LinkedHashSet; 25 | import java.util.Set; 26 | 27 | import static org.apache.dubbo.spring.boot.actuate.health.DubboHealthIndicatorProperties.PREFIX; 28 | 29 | /** 30 | * Dubbo {@link HealthIndicator} Properties 31 | * 32 | * @see HealthIndicator 33 | * @since 2.7.0 34 | */ 35 | @ConfigurationProperties(prefix = PREFIX, ignoreUnknownFields = false) 36 | public class DubboHealthIndicatorProperties { 37 | 38 | /** 39 | * The prefix of {@link DubboHealthIndicatorProperties} 40 | */ 41 | public static final String PREFIX = "management.health.dubbo"; 42 | 43 | private Status status = new Status(); 44 | 45 | public Status getStatus() { 46 | return status; 47 | } 48 | 49 | public void setStatus(Status status) { 50 | this.status = status; 51 | } 52 | 53 | /** 54 | * The nested class for {@link StatusChecker}'s names 55 | *
56 |      * registry= org.apache.dubbo.registry.status.RegistryStatusChecker
57 |      * spring= org.apache.dubbo.config.spring.status.SpringStatusChecker
58 |      * datasource= org.apache.dubbo.config.spring.status.DataSourceStatusChecker
59 |      * memory= org.apache.dubbo.common.status.support.MemoryStatusChecker
60 |      * load= org.apache.dubbo.common.status.support.LoadStatusChecker
61 |      * server= org.apache.dubbo.rpc.protocol.dubbo.status.ServerStatusChecker
62 |      * threadpool= org.apache.dubbo.rpc.protocol.dubbo.status.ThreadPoolStatusChecker
63 |      * 
64 | * 65 | * @see StatusChecker 66 | */ 67 | public static class Status { 68 | 69 | /** 70 | * The defaults names of {@link StatusChecker} 71 | *

72 | * The defaults : "memory", "load" 73 | */ 74 | private Set defaults = new LinkedHashSet<>(Arrays.asList("memory", "load")); 75 | 76 | /** 77 | * The extra names of {@link StatusChecker} 78 | */ 79 | private Set extras = new LinkedHashSet<>(); 80 | 81 | public Set getDefaults() { 82 | return defaults; 83 | } 84 | 85 | public void setDefaults(Set defaults) { 86 | this.defaults = defaults; 87 | } 88 | 89 | public Set getExtras() { 90 | return extras; 91 | } 92 | 93 | public void setExtras(Set extras) { 94 | this.extras = extras; 95 | } 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/actuator/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | org.apache.dubbo.spring.boot.actuate.autoconfigure.DubboEndpointAutoConfiguration,\ 3 | org.apache.dubbo.spring.boot.actuate.autoconfigure.DubboHealthIndicatorAutoConfiguration,\ 4 | org.apache.dubbo.spring.boot.actuate.autoconfigure.DubboEndpointMetadataAutoConfiguration 5 | org.springframework.boot.actuate.autoconfigure.ManagementContextConfiguration=\ 6 | org.apache.dubbo.spring.boot.actuate.autoconfigure.DubboMvcEndpointManagementContextConfiguration -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/actuator/src/test/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.actuate.health; 18 | 19 | import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig; 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | import org.junit.runner.RunWith; 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | import org.springframework.boot.actuate.health.Health; 25 | import org.springframework.boot.actuate.health.Status; 26 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 27 | import org.springframework.boot.test.context.SpringBootTest; 28 | import org.springframework.test.context.TestPropertySource; 29 | import org.springframework.test.context.junit4.SpringRunner; 30 | 31 | import java.util.Map; 32 | 33 | /** 34 | * {@link DubboHealthIndicator} Test 35 | * 36 | * @see DubboHealthIndicator 37 | * @since 2.7.0 38 | */ 39 | @RunWith(SpringRunner.class) 40 | @TestPropertySource(properties = { 41 | "dubbo.protocol.id = dubbo-protocol", 42 | "dubbo.protocol.name = dubbo", 43 | "dubbo.protocol.port = 12345", 44 | "dubbo.protocol.status = registry", 45 | "dubbo.provider.id = dubbo-provider", 46 | "dubbo.provider.status = server", 47 | "management.health.dubbo.status.defaults = memory", 48 | "management.health.dubbo.status.extras = load,threadpool" 49 | }) 50 | @SpringBootTest( 51 | classes = { 52 | DubboHealthIndicator.class, 53 | DubboHealthIndicatorTest.class 54 | } 55 | ) 56 | @EnableConfigurationProperties(DubboHealthIndicatorProperties.class) 57 | @EnableDubboConfig 58 | public class DubboHealthIndicatorTest { 59 | 60 | @Autowired 61 | private DubboHealthIndicator dubboHealthIndicator; 62 | 63 | @Test 64 | public void testResolveStatusCheckerNamesMap() { 65 | 66 | Map statusCheckerNamesMap = dubboHealthIndicator.resolveStatusCheckerNamesMap(); 67 | 68 | Assert.assertEquals(5, statusCheckerNamesMap.size()); 69 | 70 | Assert.assertEquals("dubbo-protocol@ProtocolConfig.getStatus()", statusCheckerNamesMap.get("registry")); 71 | Assert.assertEquals("dubbo-provider@ProviderConfig.getStatus()", statusCheckerNamesMap.get("server")); 72 | Assert.assertEquals("management.health.dubbo.status.defaults", statusCheckerNamesMap.get("memory")); 73 | Assert.assertEquals("management.health.dubbo.status.extras", statusCheckerNamesMap.get("load")); 74 | Assert.assertEquals("management.health.dubbo.status.extras", statusCheckerNamesMap.get("threadpool")); 75 | 76 | } 77 | 78 | @Test 79 | public void testHealth() { 80 | 81 | Health health = dubboHealthIndicator.health(); 82 | 83 | Assert.assertEquals(Status.UNKNOWN, health.getStatus()); 84 | 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/autoconfigure/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | org.apache.dubbo 23 | dubbo-spring-boot-compatible 24 | ${revision} 25 | ../pom.xml 26 | 27 | 4.0.0 28 | 29 | dubbo-spring-boot-autoconfigure-compatible 30 | Apache Dubbo Spring Boot :: Compatible :: Auto-Configure 31 | Apache Dubbo Spring Boot Compatible for Spring Boot 1.x Auto-Configure 32 | 33 | 34 | 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-autoconfigure 40 | true 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-logging 46 | true 47 | 48 | 49 | 50 | 51 | org.springframework.boot 52 | spring-boot-configuration-processor 53 | true 54 | 55 | 56 | 57 | 58 | org.apache.dubbo 59 | dubbo 60 | 61 | 62 | 63 | 64 | org.springframework.boot 65 | spring-boot-starter-test 66 | test 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/DubboRelaxedBindingAutoConfiguration.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 org.apache.dubbo.spring.boot.autoconfigure; 18 | 19 | import com.alibaba.spring.context.config.ConfigurationBeanBinder; 20 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 22 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 23 | import org.springframework.boot.bind.RelaxedPropertyResolver; 24 | import org.springframework.context.annotation.Bean; 25 | import org.springframework.context.annotation.Configuration; 26 | import org.springframework.context.annotation.Scope; 27 | import org.springframework.core.env.Environment; 28 | import org.springframework.core.env.PropertyResolver; 29 | 30 | import static org.apache.dubbo.spring.boot.util.DubboUtils.BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME; 31 | import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_PREFIX; 32 | import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_SCAN_PREFIX; 33 | import static org.apache.dubbo.spring.boot.util.DubboUtils.RELAXED_DUBBO_CONFIG_BINDER_BEAN_NAME; 34 | import static org.springframework.beans.factory.config.ConfigurableBeanFactory.SCOPE_PROTOTYPE; 35 | 36 | /** 37 | * Dubbo Relaxed Binding Auto-{@link Configuration} for Spring Boot 1.x 38 | */ 39 | @ConditionalOnProperty(prefix = DUBBO_PREFIX, name = "enabled", matchIfMissing = true) 40 | @ConditionalOnClass(name = "org.springframework.boot.bind.RelaxedPropertyResolver") 41 | @Configuration 42 | public class DubboRelaxedBindingAutoConfiguration { 43 | 44 | @Bean(name = BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME) 45 | public PropertyResolver dubboScanBasePackagesPropertyResolver(Environment environment) { 46 | return new RelaxedPropertyResolver(environment, DUBBO_SCAN_PREFIX); 47 | } 48 | 49 | @ConditionalOnMissingBean(name = RELAXED_DUBBO_CONFIG_BINDER_BEAN_NAME, value = ConfigurationBeanBinder.class) 50 | @Bean(RELAXED_DUBBO_CONFIG_BINDER_BEAN_NAME) 51 | @Scope(scopeName = SCOPE_PROTOTYPE) 52 | public ConfigurationBeanBinder relaxedDubboConfigBinder() { 53 | return new RelaxedDubboConfigBinder(); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.autoconfigure; 18 | 19 | import org.apache.dubbo.config.spring.context.properties.DubboConfigBinder; 20 | 21 | import com.alibaba.spring.context.config.ConfigurationBeanBinder; 22 | import org.springframework.beans.MutablePropertyValues; 23 | import org.springframework.boot.bind.RelaxedDataBinder; 24 | 25 | import java.util.Map; 26 | 27 | 28 | /** 29 | * Spring Boot Relaxed {@link DubboConfigBinder} implementation 30 | * 31 | * @since 2.7.0 32 | */ 33 | class RelaxedDubboConfigBinder implements ConfigurationBeanBinder { 34 | 35 | @Override 36 | public void bind(Map configurationProperties, boolean ignoreUnknownFields, 37 | boolean ignoreInvalidFields, Object configurationBean) { 38 | RelaxedDataBinder relaxedDataBinder = new RelaxedDataBinder(configurationBean); 39 | // Set ignored* 40 | relaxedDataBinder.setIgnoreInvalidFields(ignoreInvalidFields); 41 | relaxedDataBinder.setIgnoreUnknownFields(ignoreUnknownFields); 42 | // Get properties under specified prefix from PropertySources 43 | // Convert Map to MutablePropertyValues 44 | MutablePropertyValues propertyValues = new MutablePropertyValues(configurationProperties); 45 | // Bind 46 | relaxedDataBinder.bind(propertyValues); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/beans/factory/config/DubboConfigBeanCustomizer.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 org.apache.dubbo.spring.boot.beans.factory.config; 18 | 19 | import org.apache.dubbo.config.AbstractConfig; 20 | import org.apache.dubbo.config.spring.context.config.NamePropertyDefaultValueDubboConfigBeanCustomizer; 21 | 22 | import org.springframework.beans.BeanUtils; 23 | 24 | import java.lang.reflect.Method; 25 | 26 | import static org.springframework.util.ReflectionUtils.findMethod; 27 | import static org.springframework.util.ReflectionUtils.invokeMethod; 28 | 29 | 30 | /** 31 | * Current implementation will be replaced {@link NamePropertyDefaultValueDubboConfigBeanCustomizer} in Dubbo 2.7.2 32 | * 33 | * @since 2.7.1 34 | * @deprecated 35 | */ 36 | @Deprecated 37 | class DubboConfigBeanCustomizer extends NamePropertyDefaultValueDubboConfigBeanCustomizer { 38 | 39 | @Override 40 | public void customize(String beanName, AbstractConfig dubboConfigBean) { 41 | boolean valid = isValidPropertyName(dubboConfigBean, beanName); 42 | if (valid) { 43 | super.customize(beanName, dubboConfigBean); 44 | } 45 | } 46 | 47 | private boolean isValidPropertyName(AbstractConfig dubboConfigBean, String propertyValue) { 48 | boolean valid = true; 49 | String propertyName = "name"; 50 | // AbstractConfig.checkName(String,String) 51 | Method method = findMethod(AbstractConfig.class, "checkName", String.class, String.class); 52 | try { 53 | if (method != null) { 54 | if (!method.isAccessible()) { 55 | method.setAccessible(true); 56 | } 57 | if (BeanUtils.getPropertyDescriptor(dubboConfigBean.getClass(), propertyName) != null) { 58 | invokeMethod(method, null, propertyName, propertyValue); 59 | } 60 | } 61 | } catch (IllegalStateException e) { 62 | valid = false; 63 | } 64 | 65 | return valid; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/beans/factory/config/OverrideBeanDefinitionRegistryPostProcessor.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 org.apache.dubbo.spring.boot.beans.factory.config; 18 | 19 | import org.springframework.beans.BeansException; 20 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; 21 | import org.springframework.beans.factory.support.BeanDefinitionRegistry; 22 | import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; 23 | 24 | import static com.alibaba.spring.util.BeanRegistrar.registerInfrastructureBean; 25 | import static org.apache.dubbo.config.spring.context.config.NamePropertyDefaultValueDubboConfigBeanCustomizer.BEAN_NAME; 26 | 27 | /** 28 | * Override {@link BeanDefinitionRegistryPostProcessor} 29 | * 30 | * @since 2.7.1 31 | */ 32 | public class OverrideBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor { 33 | 34 | @Override 35 | public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { 36 | registerInfrastructureBean(registry, BEAN_NAME, DubboConfigBeanCustomizer.class); 37 | } 38 | 39 | @Override 40 | public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/context/DubboApplicationContextInitializer.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 org.apache.dubbo.spring.boot.context; 18 | 19 | import org.apache.dubbo.spring.boot.beans.factory.config.OverrideBeanDefinitionRegistryPostProcessor; 20 | 21 | import org.springframework.context.ApplicationContextInitializer; 22 | import org.springframework.context.ConfigurableApplicationContext; 23 | import org.springframework.core.Ordered; 24 | 25 | /** 26 | * Dubbo {@link ApplicationContextInitializer} implementation 27 | * 28 | * @see ApplicationContextInitializer 29 | * @since 2.7.1 30 | */ 31 | public class DubboApplicationContextInitializer implements ApplicationContextInitializer, Ordered { 32 | 33 | @Override 34 | public void initialize(ConfigurableApplicationContext applicationContext) { 35 | overrideBeanDefinitions(applicationContext); 36 | } 37 | 38 | private void overrideBeanDefinitions(ConfigurableApplicationContext applicationContext) { 39 | applicationContext.addBeanFactoryPostProcessor(new OverrideBeanDefinitionRegistryPostProcessor()); 40 | // @since 2.7.5 DubboConfigBeanDefinitionConflictProcessor has been removed 41 | // @see {@link DubboConfigBeanDefinitionConflictApplicationListener} 42 | // applicationContext.addBeanFactoryPostProcessor(new DubboConfigBeanDefinitionConflictProcessor()); 43 | } 44 | 45 | @Override 46 | public int getOrder() { 47 | return HIGHEST_PRECEDENCE; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.context.event; 18 | 19 | import org.apache.dubbo.common.utils.ConfigUtils; 20 | import org.apache.dubbo.config.AbstractConfig; 21 | import org.slf4j.Logger; 22 | import org.slf4j.LoggerFactory; 23 | import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; 24 | import org.springframework.context.ApplicationListener; 25 | import org.springframework.core.annotation.Order; 26 | import org.springframework.core.env.ConfigurableEnvironment; 27 | import org.springframework.core.env.Environment; 28 | 29 | import java.util.SortedMap; 30 | 31 | import static org.apache.dubbo.spring.boot.util.DubboUtils.DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE; 32 | import static org.apache.dubbo.spring.boot.util.DubboUtils.OVERRIDE_CONFIG_FULL_PROPERTY_NAME; 33 | import static org.apache.dubbo.spring.boot.util.DubboUtils.filterDubboProperties; 34 | 35 | /** 36 | * {@link ApplicationListener} to override the dubbo properties from {@link Environment}into 37 | * {@link ConfigUtils#getProperties() Dubbo Config}. 38 | * {@link AbstractConfig Dubbo Config} on {@link ApplicationEnvironmentPreparedEvent}. 39 | *

40 | * 41 | * @see ConfigUtils 42 | * @since 2.7.0 43 | */ 44 | @Order // LOWEST_PRECEDENCE Make sure last execution 45 | public class OverrideDubboConfigApplicationListener implements ApplicationListener { 46 | 47 | @Override 48 | public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { 49 | 50 | /** 51 | * Gets Logger After LoggingSystem configuration ready 52 | * @see LoggingApplicationListener 53 | */ 54 | final Logger logger = LoggerFactory.getLogger(getClass()); 55 | 56 | ConfigurableEnvironment environment = event.getEnvironment(); 57 | 58 | boolean override = environment.getProperty(OVERRIDE_CONFIG_FULL_PROPERTY_NAME, boolean.class, 59 | DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE); 60 | 61 | if (override) { 62 | 63 | SortedMap dubboProperties = filterDubboProperties(environment); 64 | 65 | ConfigUtils.getProperties().putAll(dubboProperties); 66 | 67 | if (logger.isInfoEnabled()) { 68 | logger.info("Dubbo Config was overridden by externalized configuration {}", dubboProperties); 69 | } 70 | } else { 71 | if (logger.isInfoEnabled()) { 72 | logger.info("Disable override Dubbo Config caused by property {} = {}", OVERRIDE_CONFIG_FULL_PROPERTY_NAME, override); 73 | } 74 | } 75 | 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.context.event; 18 | 19 | import org.apache.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.context.ApplicationListener; 25 | import org.springframework.core.Ordered; 26 | import org.springframework.core.annotation.Order; 27 | 28 | import java.util.concurrent.atomic.AtomicBoolean; 29 | 30 | import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_GITHUB_URL; 31 | import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_MAILING_LIST; 32 | import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_SPRING_BOOT_GITHUB_URL; 33 | import static org.apache.dubbo.spring.boot.util.DubboUtils.LINE_SEPARATOR; 34 | 35 | /** 36 | * Dubbo Welcome Logo {@link ApplicationListener} 37 | * 38 | * @see ApplicationListener 39 | * @since 2.7.0 40 | */ 41 | @Order(Ordered.HIGHEST_PRECEDENCE + 20 + 1) // After LoggingApplicationListener#DEFAULT_ORDER 42 | public class WelcomeLogoApplicationListener implements ApplicationListener { 43 | 44 | private static AtomicBoolean processed = new AtomicBoolean(false); 45 | 46 | @Override 47 | public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { 48 | 49 | // Skip if processed before, prevent duplicated execution in Hierarchical ApplicationContext 50 | if (processed.get()) { 51 | return; 52 | } 53 | 54 | /** 55 | * Gets Logger After LoggingSystem configuration ready 56 | * @see LoggingApplicationListener 57 | */ 58 | final Logger logger = LoggerFactory.getLogger(getClass()); 59 | 60 | String bannerText = buildBannerText(); 61 | 62 | if (logger.isInfoEnabled()) { 63 | logger.info(bannerText); 64 | } else { 65 | System.out.print(bannerText); 66 | } 67 | 68 | // mark processed to be true 69 | processed.compareAndSet(false, true); 70 | } 71 | 72 | String buildBannerText() { 73 | 74 | StringBuilder bannerTextBuilder = new StringBuilder(); 75 | 76 | bannerTextBuilder 77 | .append(LINE_SEPARATOR) 78 | .append(LINE_SEPARATOR) 79 | .append(" :: Dubbo Spring Boot (v").append(Version.getVersion(getClass(), Version.getVersion())).append(") : ") 80 | .append(DUBBO_SPRING_BOOT_GITHUB_URL) 81 | .append(LINE_SEPARATOR) 82 | .append(" :: Dubbo (v").append(Version.getVersion()).append(") : ") 83 | .append(DUBBO_GITHUB_URL) 84 | .append(LINE_SEPARATOR) 85 | .append(" :: Discuss group : ") 86 | .append(DUBBO_MAILING_LIST) 87 | .append(LINE_SEPARATOR) 88 | ; 89 | 90 | return bannerTextBuilder.toString(); 91 | 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/autoconfigure/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | org.apache.dubbo.spring.boot.autoconfigure.DubboAutoConfiguration,\ 3 | org.apache.dubbo.spring.boot.autoconfigure.DubboRelaxedBindingAutoConfiguration 4 | org.springframework.context.ApplicationListener=\ 5 | org.apache.dubbo.spring.boot.context.event.OverrideDubboConfigApplicationListener,\ 6 | org.apache.dubbo.spring.boot.context.event.DubboConfigBeanDefinitionConflictApplicationListener,\ 7 | org.apache.dubbo.spring.boot.context.event.WelcomeLogoApplicationListener,\ 8 | org.apache.dubbo.spring.boot.context.event.AwaitingNonWebApplicationListener 9 | org.springframework.boot.env.EnvironmentPostProcessor=\ 10 | org.apache.dubbo.spring.boot.env.DubboDefaultPropertiesEnvironmentPostProcessor 11 | org.springframework.context.ApplicationContextInitializer=\ 12 | org.apache.dubbo.spring.boot.context.DubboApplicationContextInitializer -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/autoconfigure/src/test/java/org/apache/dubbo/spring/boot/autoconfigure/CompatibleDubboAutoConfigurationTest.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 org.apache.dubbo.spring.boot.autoconfigure; 18 | 19 | import org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor; 20 | import org.apache.dubbo.config.spring.beans.factory.annotation.ServiceAnnotationBeanPostProcessor; 21 | 22 | import org.junit.Assert; 23 | import org.junit.Test; 24 | import org.junit.runner.RunWith; 25 | import org.springframework.beans.factory.ObjectProvider; 26 | import org.springframework.beans.factory.annotation.Autowired; 27 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 28 | import org.springframework.boot.test.context.SpringBootTest; 29 | import org.springframework.context.annotation.PropertySource; 30 | import org.springframework.test.context.junit4.SpringRunner; 31 | 32 | /** 33 | * {@link DubboAutoConfiguration} Test 34 | * @see DubboAutoConfiguration 35 | */ 36 | @RunWith(SpringRunner.class) 37 | @SpringBootTest(classes = { 38 | CompatibleDubboAutoConfigurationTest.class 39 | }, properties = { 40 | "dubbo.scan.base-packages = org.apache.dubbo.spring.boot.autoconfigure" 41 | }) 42 | @EnableAutoConfiguration 43 | @PropertySource(value = "classpath:/META-INF/dubbo.properties") 44 | public class CompatibleDubboAutoConfigurationTest { 45 | 46 | @Autowired 47 | private ObjectProvider serviceAnnotationBeanPostProcessor; 48 | 49 | @Autowired 50 | private ObjectProvider referenceAnnotationBeanPostProcessor; 51 | 52 | @Test 53 | public void testBeans() { 54 | Assert.assertNotNull(serviceAnnotationBeanPostProcessor); 55 | Assert.assertNotNull(serviceAnnotationBeanPostProcessor.getIfAvailable()); 56 | Assert.assertNotNull(referenceAnnotationBeanPostProcessor); 57 | Assert.assertNotNull(referenceAnnotationBeanPostProcessor.getIfAvailable()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/autoconfigure/src/test/java/org/apache/dubbo/spring/boot/autoconfigure/CompatibleDubboAutoConfigurationTestWithoutProperties.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 org.apache.dubbo.spring.boot.autoconfigure; 18 | 19 | import org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor; 20 | import org.apache.dubbo.config.spring.beans.factory.annotation.ServiceAnnotationBeanPostProcessor; 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.autoconfigure.EnableAutoConfiguration; 26 | import org.springframework.boot.test.context.SpringBootTest; 27 | import org.springframework.test.context.junit4.SpringRunner; 28 | 29 | /** 30 | * {@link DubboAutoConfiguration} Test 31 | * 32 | * @see DubboAutoConfiguration 33 | */ 34 | @RunWith(SpringRunner.class) 35 | @SpringBootTest(classes = CompatibleDubboAutoConfigurationTestWithoutProperties.class) 36 | @EnableAutoConfiguration 37 | public class CompatibleDubboAutoConfigurationTestWithoutProperties { 38 | 39 | @Autowired(required = false) 40 | private ServiceAnnotationBeanPostProcessor serviceAnnotationBeanPostProcessor; 41 | 42 | @Autowired 43 | private ReferenceAnnotationBeanPostProcessor referenceAnnotationBeanPostProcessor; 44 | 45 | @Test 46 | public void testBeans() { 47 | Assert.assertNull(serviceAnnotationBeanPostProcessor); 48 | Assert.assertNotNull(referenceAnnotationBeanPostProcessor); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/autoconfigure/src/test/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.autoconfigure; 18 | 19 | import org.apache.dubbo.config.ApplicationConfig; 20 | import org.apache.dubbo.config.ProtocolConfig; 21 | import org.apache.dubbo.config.RegistryConfig; 22 | 23 | import com.alibaba.spring.context.config.ConfigurationBeanBinder; 24 | import org.junit.Assert; 25 | import org.junit.Test; 26 | import org.junit.runner.RunWith; 27 | import org.springframework.beans.factory.annotation.Autowired; 28 | import org.springframework.core.env.ConfigurableEnvironment; 29 | import org.springframework.test.context.ContextConfiguration; 30 | import org.springframework.test.context.TestPropertySource; 31 | import org.springframework.test.context.junit4.SpringRunner; 32 | 33 | import java.util.Map; 34 | 35 | import static com.alibaba.spring.util.PropertySourcesUtils.getSubProperties; 36 | 37 | /** 38 | * {@link RelaxedDubboConfigBinder} Test 39 | */ 40 | @RunWith(SpringRunner.class) 41 | @TestPropertySource(properties = { 42 | "dubbo.application.NAME=hello", 43 | "dubbo.application.owneR=world", 44 | "dubbo.registry.Address=10.20.153.17", 45 | "dubbo.protocol.pORt=20881", 46 | "dubbo.service.invoke.timeout=2000", 47 | }) 48 | @ContextConfiguration(classes = RelaxedDubboConfigBinder.class) 49 | public class RelaxedDubboConfigBinderTest { 50 | 51 | @Autowired 52 | private ConfigurationBeanBinder dubboConfigBinder; 53 | 54 | @Autowired 55 | private ConfigurableEnvironment environment; 56 | 57 | @Test 58 | public void testBinder() { 59 | 60 | ApplicationConfig applicationConfig = new ApplicationConfig(); 61 | Map properties = getSubProperties(environment.getPropertySources(), "dubbo.application"); 62 | dubboConfigBinder.bind(properties, true, true, applicationConfig); 63 | Assert.assertEquals("hello", applicationConfig.getName()); 64 | Assert.assertEquals("world", applicationConfig.getOwner()); 65 | 66 | RegistryConfig registryConfig = new RegistryConfig(); 67 | properties = getSubProperties(environment.getPropertySources(), "dubbo.registry"); 68 | dubboConfigBinder.bind(properties, true, true, registryConfig); 69 | Assert.assertEquals("10.20.153.17", registryConfig.getAddress()); 70 | 71 | ProtocolConfig protocolConfig = new ProtocolConfig(); 72 | properties = getSubProperties(environment.getPropertySources(), "dubbo.protocol"); 73 | dubboConfigBinder.bind(properties, true, true, protocolConfig); 74 | Assert.assertEquals(Integer.valueOf(20881), protocolConfig.getPort()); 75 | 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/autoconfigure/src/test/java/org/apache/dubbo/spring/boot/beans/factory/config/DubboConfigBeanDefinitionConflictProcessorTest.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 org.apache.dubbo.spring.boot.beans.factory.config; 18 | 19 | import org.apache.dubbo.config.ApplicationConfig; 20 | import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig; 21 | 22 | import org.junit.After; 23 | import org.junit.Assert; 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 27 | import org.springframework.context.annotation.ImportResource; 28 | import org.springframework.context.annotation.PropertySource; 29 | import org.springframework.core.Ordered; 30 | 31 | import java.util.Map; 32 | 33 | 34 | /** 35 | * {@link DubboConfigBeanDefinitionConflictProcessor} Test 36 | * 37 | * @since 2.7.1 38 | */ 39 | public class DubboConfigBeanDefinitionConflictProcessorTest { 40 | 41 | private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); 42 | 43 | @Before 44 | public void init() { 45 | context.addBeanFactoryPostProcessor(new DubboConfigBeanDefinitionConflictProcessor()); 46 | } 47 | 48 | @After 49 | public void destroy() { 50 | context.close(); 51 | } 52 | 53 | @Test 54 | public void testOrder() { 55 | Assert.assertEquals(Ordered.LOWEST_PRECEDENCE, new DubboConfigBeanDefinitionConflictProcessor().getOrder()); 56 | } 57 | 58 | @Test 59 | public void testNormalCase() { 60 | 61 | System.setProperty("dubbo.application.name", "test-dubbo-application"); 62 | 63 | context.register(DubboConfig.class); 64 | 65 | context.refresh(); 66 | 67 | ApplicationConfig applicationConfig = context.getBean(ApplicationConfig.class); 68 | 69 | Assert.assertEquals("test-dubbo-application", applicationConfig.getName()); 70 | } 71 | 72 | @Test 73 | public void testDuplicatedConfigsCase() { 74 | 75 | context.register(PropertySourceConfig.class, DubboConfig.class); 76 | 77 | context.register(XmlConfig.class); 78 | 79 | context.refresh(); 80 | 81 | Map beansMap = context.getBeansOfType(ApplicationConfig.class); 82 | 83 | ApplicationConfig applicationConfig = beansMap.get("dubbo-consumer-2.7.x"); 84 | 85 | Assert.assertEquals(1, beansMap.size()); 86 | 87 | Assert.assertEquals("dubbo-consumer-2.7.x", applicationConfig.getName()); 88 | } 89 | 90 | @Test(expected = IllegalStateException.class) 91 | public void testFailedCase() { 92 | context.register(ApplicationConfig.class); 93 | testDuplicatedConfigsCase(); 94 | } 95 | 96 | @EnableDubboConfig 97 | static class DubboConfig { 98 | 99 | } 100 | 101 | @PropertySource("classpath:/META-INF/dubbo.properties") 102 | static class PropertySourceConfig { 103 | 104 | } 105 | 106 | @ImportResource("classpath:/META-INF/spring/dubbo-context.xml") 107 | static class XmlConfig { 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/autoconfigure/src/test/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.context.event; 18 | 19 | import org.junit.Assert; 20 | import org.junit.Test; 21 | import org.springframework.boot.builder.SpringApplicationBuilder; 22 | 23 | import java.util.concurrent.atomic.AtomicBoolean; 24 | 25 | /** 26 | * {@link AwaitingNonWebApplicationListener} Test 27 | */ 28 | public class AwaitingNonWebApplicationListenerTest { 29 | 30 | @Test 31 | public void init() { 32 | AtomicBoolean awaited = AwaitingNonWebApplicationListener.getAwaited(); 33 | awaited.set(false); 34 | 35 | } 36 | 37 | @Test 38 | public void testSingleContextNonWebApplication() { 39 | new SpringApplicationBuilder(Object.class) 40 | .web(false) 41 | .run().close(); 42 | AtomicBoolean awaited = AwaitingNonWebApplicationListener.getAwaited(); 43 | Assert.assertTrue(awaited.get()); 44 | } 45 | 46 | @Test 47 | public void testMultipleContextNonWebApplication() { 48 | new SpringApplicationBuilder(Object.class) 49 | .parent(Object.class) 50 | .web(false) 51 | .run().close(); 52 | AtomicBoolean awaited = AwaitingNonWebApplicationListener.getAwaited(); 53 | Assert.assertTrue(awaited.get()); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/autoconfigure/src/test/java/org/apache/dubbo/spring/boot/context/event/DubboConfigBeanDefinitionConflictApplicationListenerTest.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 org.apache.dubbo.spring.boot.context.event; 18 | 19 | import org.apache.dubbo.config.ApplicationConfig; 20 | import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig; 21 | import org.apache.dubbo.spring.boot.beans.factory.config.DubboConfigBeanDefinitionConflictProcessor; 22 | 23 | import org.junit.After; 24 | import org.junit.Assert; 25 | import org.junit.Before; 26 | import org.junit.Test; 27 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 28 | import org.springframework.context.annotation.ImportResource; 29 | import org.springframework.context.annotation.PropertySource; 30 | import org.springframework.core.Ordered; 31 | 32 | import java.util.Map; 33 | 34 | 35 | /** 36 | * {@link DubboConfigBeanDefinitionConflictApplicationListener} Test 37 | * @since 2.7.5 38 | */ 39 | public class DubboConfigBeanDefinitionConflictApplicationListenerTest { 40 | 41 | private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); 42 | 43 | @Before 44 | public void init() { 45 | context.addApplicationListener(new DubboConfigBeanDefinitionConflictApplicationListener()); 46 | } 47 | 48 | @After 49 | public void destroy() { 50 | context.close(); 51 | } 52 | 53 | @Test 54 | public void testOrder() { 55 | Assert.assertEquals(Ordered.LOWEST_PRECEDENCE, new DubboConfigBeanDefinitionConflictProcessor().getOrder()); 56 | } 57 | 58 | @Test 59 | public void testNormalCase() { 60 | 61 | System.setProperty("dubbo.application.name", "test-dubbo-application"); 62 | 63 | context.register(DubboConfig.class); 64 | 65 | context.refresh(); 66 | 67 | ApplicationConfig applicationConfig = context.getBean(ApplicationConfig.class); 68 | 69 | Assert.assertEquals("test-dubbo-application", applicationConfig.getName()); 70 | } 71 | 72 | @Test 73 | public void testDuplicatedConfigsCase() { 74 | 75 | context.register(PropertySourceConfig.class, DubboConfig.class); 76 | 77 | context.register(XmlConfig.class); 78 | 79 | context.refresh(); 80 | 81 | Map beansMap = context.getBeansOfType(ApplicationConfig.class); 82 | 83 | ApplicationConfig applicationConfig = beansMap.get("dubbo-consumer-2.7.x"); 84 | 85 | Assert.assertEquals(1, beansMap.size()); 86 | 87 | Assert.assertEquals("dubbo-consumer-2.7.x", applicationConfig.getName()); 88 | } 89 | 90 | @Test(expected = IllegalStateException.class) 91 | public void testFailedCase() { 92 | context.register(ApplicationConfig.class); 93 | testDuplicatedConfigsCase(); 94 | } 95 | 96 | @EnableDubboConfig 97 | static class DubboConfig { 98 | 99 | } 100 | 101 | @PropertySource("classpath:/META-INF/dubbo.properties") 102 | static class PropertySourceConfig { 103 | 104 | } 105 | 106 | @ImportResource("classpath:/META-INF/spring/dubbo-context.xml") 107 | static class XmlConfig { 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/autoconfigure/src/test/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.context.event; 18 | 19 | import org.apache.dubbo.common.utils.ConfigUtils; 20 | import org.junit.Assert; 21 | import org.junit.BeforeClass; 22 | import org.junit.Test; 23 | import org.junit.runner.RunWith; 24 | import org.springframework.boot.test.context.SpringBootTest; 25 | import org.springframework.test.context.TestPropertySource; 26 | import org.springframework.test.context.junit4.SpringRunner; 27 | 28 | import java.util.Properties; 29 | 30 | /** 31 | * {@link OverrideDubboConfigApplicationListener} Test 32 | * 33 | * @see OverrideDubboConfigApplicationListener 34 | * @since 2.7.0 35 | */ 36 | @RunWith(SpringRunner.class) 37 | @TestPropertySource( 38 | properties = { 39 | "dubbo.config.override = false", 40 | "dubbo.application.name = dubbo-demo-application", 41 | "dubbo.module.name = dubbo-demo-module", 42 | } 43 | ) 44 | @SpringBootTest( 45 | classes = {OverrideDubboConfigApplicationListener.class} 46 | ) 47 | public class OverrideDubboConfigApplicationListenerDisableTest { 48 | 49 | @BeforeClass 50 | public static void init() { 51 | ConfigUtils.getProperties().clear(); 52 | } 53 | 54 | @Test 55 | public void testOnApplicationEvent() { 56 | 57 | Properties properties = ConfigUtils.getProperties(); 58 | 59 | Assert.assertTrue(properties.isEmpty()); 60 | Assert.assertNull(properties.get("dubbo.application.name")); 61 | Assert.assertNull(properties.get("dubbo.module.name")); 62 | 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/autoconfigure/src/test/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.context.event; 18 | 19 | import org.apache.dubbo.common.utils.ConfigUtils; 20 | import org.junit.Assert; 21 | import org.junit.BeforeClass; 22 | import org.junit.Test; 23 | import org.junit.runner.RunWith; 24 | import org.springframework.boot.test.context.SpringBootTest; 25 | import org.springframework.test.context.TestPropertySource; 26 | import org.springframework.test.context.junit4.SpringRunner; 27 | 28 | import java.util.Properties; 29 | 30 | /** 31 | * {@link OverrideDubboConfigApplicationListener} Test 32 | * 33 | * @see OverrideDubboConfigApplicationListener 34 | * @since 2.7.0 35 | */ 36 | @RunWith(SpringRunner.class) 37 | @TestPropertySource( 38 | properties = { 39 | "dubbo.application.name = dubbo-demo-application", 40 | "dubbo.module.name = dubbo-demo-module", 41 | "dubbo.registry.address = zookeeper://192.168.99.100:32770" 42 | } 43 | ) 44 | @SpringBootTest( 45 | classes = {OverrideDubboConfigApplicationListener.class} 46 | ) 47 | public class OverrideDubboConfigApplicationListenerTest { 48 | 49 | @BeforeClass 50 | public static void init() { 51 | ConfigUtils.getProperties().clear(); 52 | } 53 | 54 | @Test 55 | public void testOnApplicationEvent() { 56 | 57 | Properties properties = ConfigUtils.getProperties(); 58 | 59 | Assert.assertEquals("dubbo-demo-application", properties.get("dubbo.application.name")); 60 | Assert.assertEquals("dubbo-demo-module", properties.get("dubbo.module.name")); 61 | Assert.assertEquals("zookeeper://192.168.99.100:32770", properties.get("dubbo.registry.address")); 62 | 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/autoconfigure/src/test/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.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.SpringRunner; 25 | 26 | /** 27 | * {@link WelcomeLogoApplicationListener} Test 28 | * 29 | * @see WelcomeLogoApplicationListener 30 | * @since 2.7.0 31 | */ 32 | @RunWith(SpringRunner.class) 33 | @SpringBootTest( 34 | classes = {WelcomeLogoApplicationListener.class} 35 | ) 36 | public class WelcomeLogoApplicationListenerTest { 37 | 38 | @Autowired 39 | private WelcomeLogoApplicationListener welcomeLogoApplicationListener; 40 | 41 | @Test 42 | public void testOnApplicationEvent() { 43 | 44 | Assert.assertNotNull(welcomeLogoApplicationListener.buildBannerText()); 45 | 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/autoconfigure/src/test/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.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 | * @see EnvironmentUtils 33 | * @since 2.7.0 34 | */ 35 | public class EnvironmentUtilsTest { 36 | 37 | @Test 38 | public void testExtraProperties() { 39 | 40 | System.setProperty("user.name", "mercyblitz"); 41 | 42 | StandardEnvironment environment = new StandardEnvironment(); 43 | 44 | Map map = new HashMap<>(); 45 | 46 | map.put("user.name", "Mercy"); 47 | 48 | MapPropertySource propertySource = new MapPropertySource("first", map); 49 | 50 | CompositePropertySource compositePropertySource = new CompositePropertySource("comp"); 51 | 52 | compositePropertySource.addFirstPropertySource(propertySource); 53 | 54 | MutablePropertySources propertySources = environment.getPropertySources(); 55 | 56 | propertySources.addFirst(compositePropertySource); 57 | 58 | Map properties = EnvironmentUtils.extractProperties(environment); 59 | 60 | Assert.assertEquals("Mercy", properties.get("user.name")); 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/autoconfigure/src/test/resources/META-INF/dubbo.properties: -------------------------------------------------------------------------------- 1 | dubbo.application.id = test-dubbo-application-id -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/autoconfigure/src/test/resources/META-INF/spring/dubbo-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /dubbo-spring-boot-compatible/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | org.apache.dubbo 23 | dubbo-spring-boot-parent 24 | ${revision} 25 | ../dubbo-spring-boot-parent/pom.xml 26 | 27 | 4.0.0 28 | 29 | dubbo-spring-boot-compatible 30 | pom 31 | Apache Dubbo Spring Boot :: Compatible 32 | Apache Dubbo Spring Boot Compatible for Spring Boot 1.x 33 | 34 | 35 | 1.5.22.RELEASE 36 | 37 | 38 | 39 | autoconfigure 40 | actuator 41 | 42 | 43 | 44 | 45 | 46 | 47 | spring-boot-1.4 48 | 49 | 1.4.7.RELEASE 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /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 | org.apache.dubbo:* 44 | 45 | 46 | com.alibaba:fastjson 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /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 | **/.flattened-pom.xml 53 | **/.travis.yml 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | org.apache.dubbo.samples 23 | dubbo-spring-boot-auto-configure-samples 24 | ${revision} 25 | ../pom.xml 26 | 27 | 4.0.0 28 | 29 | dubbo-spring-boot-auto-configure-consumer-sample 30 | Apache Dubbo Spring Boot :: Samples : Auto-Configure :: Consumer Sample 31 | 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter 37 | 38 | 39 | 40 | org.apache.dubbo 41 | dubbo-spring-boot-starter 42 | ${revision} 43 | 44 | 45 | 46 | org.apache.dubbo.samples 47 | dubbo-spring-boot-sample-api 48 | ${revision} 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | ${spring-boot.version} 59 | 60 | 61 | 62 | repackage 63 | 64 | 65 | 66 | 67 | false 68 | ${project.artifactId}-${spring-boot.version} 69 | ${user.dir}/target 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.demo.consumer.bootstrap; 18 | 19 | import org.apache.dubbo.config.annotation.Reference; 20 | import org.apache.dubbo.spring.boot.demo.consumer.DemoService; 21 | import org.slf4j.Logger; 22 | import org.slf4j.LoggerFactory; 23 | import org.springframework.boot.ApplicationRunner; 24 | import org.springframework.boot.SpringApplication; 25 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 26 | import org.springframework.context.annotation.Bean; 27 | 28 | /** 29 | * Dubbo Auto Configuration Consumer Bootstrap 30 | * 31 | * @since 2.7.0 32 | */ 33 | @EnableAutoConfiguration 34 | public class DubboAutoConfigurationConsumerBootstrap { 35 | 36 | private final Logger logger = LoggerFactory.getLogger(getClass()); 37 | 38 | @Reference(version = "1.0.0", url = "dubbo://127.0.0.1:12345") 39 | private DemoService demoService; 40 | 41 | public static void main(String[] args) { 42 | SpringApplication.run(DubboAutoConfigurationConsumerBootstrap.class).close(); 43 | } 44 | 45 | @Bean 46 | public ApplicationRunner runner() { 47 | return args -> logger.info(demoService.sayHello("mercyblitz")); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/auto-configure-samples/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | org.apache.dubbo.samples 23 | dubbo-spring-boot-samples 24 | ${revision} 25 | ../pom.xml 26 | 27 | 4.0.0 28 | 29 | dubbo-spring-boot-auto-configure-samples 30 | Apache Dubbo Spring Boot :: Samples : Auto-Configure 31 | Apache Dubbo Spring Boot Auto-Configure Samples 32 | pom 33 | 34 | 35 | consumer-sample 36 | provider-sample 37 | 38 | 39 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/auto-configure-samples/provider-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | org.apache.dubbo.samples 23 | dubbo-spring-boot-auto-configure-samples 24 | ${revision} 25 | ../pom.xml 26 | 27 | 4.0.0 28 | 29 | dubbo-spring-boot-auto-configure-provider-sample 30 | Apache Dubbo Spring Boot :: Samples : Auto-Configure :: Provider Sample 31 | 32 | 33 | 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter 38 | 39 | 40 | 41 | org.apache.dubbo 42 | dubbo-spring-boot-starter 43 | ${revision} 44 | 45 | 46 | 47 | org.apache.dubbo.samples 48 | dubbo-spring-boot-sample-api 49 | ${revision} 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | org.springframework.boot 58 | spring-boot-maven-plugin 59 | ${spring-boot.version} 60 | 61 | 62 | 63 | repackage 64 | 65 | 66 | 67 | 68 | false 69 | ${project.artifactId}-${spring-boot.version} 70 | ${user.dir}/target 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.demo.provider.bootstrap; 18 | 19 | import org.apache.dubbo.spring.boot.demo.provider.service.DefaultDemoService; 20 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 21 | import org.springframework.boot.builder.SpringApplicationBuilder; 22 | 23 | /** 24 | * Dubbo Auto-Configuration Provider Bootstrap 25 | * 26 | * @see DefaultDemoService 27 | * @since 2.7.0 28 | */ 29 | @EnableAutoConfiguration 30 | public class DubboAutoConfigurationProviderBootstrap { 31 | 32 | public static void main(String[] args) { 33 | new SpringApplicationBuilder(DubboAutoConfigurationProviderBootstrap.class) 34 | .run(args); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.demo.provider.service; 18 | 19 | import org.apache.dubbo.config.annotation.Service; 20 | import org.apache.dubbo.spring.boot.demo.consumer.DemoService; 21 | import org.springframework.beans.factory.annotation.Value; 22 | 23 | /** 24 | * Default {@link DemoService} 25 | * 26 | * @see DemoService 27 | * @since 2.7.0 28 | */ 29 | @Service(version = "1.0.0") 30 | public class DefaultDemoService implements DemoService { 31 | 32 | /** 33 | * The default value of ${dubbo.application.name} is ${spring.application.name} 34 | */ 35 | @Value("${dubbo.application.name}") 36 | private String serviceName; 37 | 38 | @Override 39 | public String sayHello(String name) { 40 | return String.format("[%s] : Hello, %s", serviceName, name); 41 | } 42 | } -------------------------------------------------------------------------------- /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: @org.apache.dubbo.config.annotation.Service 4 | dubbo.scan.base-packages=org.apache.dubbo.spring.boot.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 -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-nacos-samples/consumer-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | dubbo-spring-boot-registry-nacos-samples 23 | org.apache.dubbo.samples 24 | ${revision} 25 | ../pom.xml 26 | 27 | 4.0.0 28 | 29 | dubbo-spring-boot-registry-nacos-consumer-sample 30 | Apache Dubbo Spring Boot :: Samples : Registry Nacos :: Consumer Sample 31 | 32 | 33 | 1.0.0-RC3 34 | 35 | 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter 41 | 42 | 43 | 44 | org.apache.dubbo 45 | dubbo-spring-boot-starter 46 | ${revision} 47 | 48 | 49 | 50 | 51 | org.apache.dubbo 52 | dubbo 53 | 54 | 55 | 56 | 57 | org.apache.dubbo 58 | dubbo-registry-nacos 59 | ${revision} 60 | 61 | 62 | 63 | com.alibaba.nacos 64 | nacos-client 65 | ${nacos.version} 66 | 67 | 68 | 69 | org.apache.dubbo.samples 70 | dubbo-spring-boot-sample-api 71 | ${revision} 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-nacos-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.demo.consumer.bootstrap; 18 | 19 | import org.apache.dubbo.config.annotation.Reference; 20 | import org.apache.dubbo.spring.boot.demo.consumer.DemoService; 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 | public static void main(String[] args) { 41 | SpringApplication.run(DubboRegistryNacosConsumerBootstrap.class).close(); 42 | } 43 | 44 | @Bean 45 | public ApplicationRunner runner() { 46 | return args -> logger.info(demoService.sayHello("mercyblitz")); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /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 | nacos: 10 | host: 127.0.0.1 11 | port: 8848 12 | 13 | dubbo: 14 | registry: 15 | address: nacos://${nacos.host}:${nacos.port} -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-nacos-samples/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | dubbo-spring-boot-samples 23 | org.apache.dubbo.samples 24 | ${revision} 25 | ../pom.xml 26 | 27 | 28 | 4.0.0 29 | 30 | dubbo-spring-boot-registry-nacos-samples 31 | Apache Dubbo Spring Boot :: Samples : Registry Nacos 32 | Apache Dubbo Spring Boot Registry Nacos Samples 33 | pom 34 | 35 | 36 | 37 | provider-sample 38 | consumer-sample 39 | 40 | 41 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | org.apache.dubbo.samples 23 | dubbo-spring-boot-registry-nacos-samples 24 | ${revision} 25 | ../pom.xml 26 | 27 | 4.0.0 28 | 29 | dubbo-spring-boot-registry-nacos-provider-sample 30 | Apache Dubbo Spring Boot :: Samples : Registry Nacos :: Provider Sample 31 | 32 | 33 | 1.1.1 34 | 35 | 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter 41 | 42 | 43 | 44 | org.apache.dubbo 45 | dubbo-spring-boot-starter 46 | ${revision} 47 | 48 | 49 | 50 | 51 | 52 | org.apache.dubbo 53 | dubbo-registry-nacos 54 | ${revision} 55 | 56 | 57 | 58 | com.alibaba.nacos 59 | nacos-client 60 | ${nacos.version} 61 | 62 | 63 | 64 | org.apache.dubbo.samples 65 | dubbo-spring-boot-sample-api 66 | ${revision} 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 | false 85 | ${project.artifactId}-${spring-boot.version} 86 | ${user.dir}/target 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.demo.provider.bootstrap; 18 | 19 | import org.apache.dubbo.spring.boot.demo.provider.service.DefaultDemoService; 20 | 21 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 22 | import org.springframework.boot.builder.SpringApplicationBuilder; 23 | 24 | /** 25 | * Dubbo Registry Nacos Provider Bootstrap 26 | * 27 | * @see DefaultDemoService 28 | * @since 2.7.0 29 | */ 30 | @EnableAutoConfiguration 31 | public class DubboRegistryNacosProviderBootstrap { 32 | 33 | public static void main(String[] args) { 34 | new SpringApplicationBuilder(DubboRegistryNacosProviderBootstrap.class) 35 | .run(args); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-nacos-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.demo.provider.service; 18 | 19 | import org.apache.dubbo.config.annotation.Service; 20 | import org.apache.dubbo.spring.boot.demo.consumer.DemoService; 21 | 22 | import org.springframework.beans.factory.annotation.Value; 23 | 24 | /** 25 | * Default {@link DemoService} 26 | * 27 | * @see DemoService 28 | * @since 2.7.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-nacos-samples/provider-sample/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Spring boot application 2 | spring.application.name=dubbo-registry-nacos-provider-sample 3 | # Base packages to scan Dubbo Component: @org.apache.dubbo.config.annotation.Service 4 | dubbo.scan.base-packages=org.apache.dubbo.spring.boot.demo.provider.service 5 | 6 | # Dubbo Application 7 | ## The default value of dubbo.application.name is ${spring.application.name} 8 | ## dubbo.application.name=${spring.application.name} 9 | nacos.server-address = 127.0.0.1 10 | nacos.port = 8848 11 | 12 | # Dubbo Protocol 13 | dubbo.protocol.name=dubbo 14 | ## Random port 15 | dubbo.protocol.port=-1 16 | 17 | ## Dubbo Registry 18 | dubbo.registry.address=nacos://${nacos.server-address}:${nacos.port} 19 | 20 | ## DemoService version 21 | demo.service.version=1.0.0 -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/consumer-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | org.apache.dubbo.samples 23 | dubbo-spring-boot-registry-zookeeper-samples 24 | ${revision} 25 | ../pom.xml 26 | 27 | 4.0.0 28 | 29 | dubbo-spring-boot-registry-zookeeper-consumer-sample 30 | Apache Dubbo Spring Boot :: Samples : Registry Zookeeper :: Consumer Sample 31 | 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter 37 | 38 | 39 | 40 | org.apache.dubbo 41 | dubbo-spring-boot-starter 42 | ${revision} 43 | 44 | 45 | 46 | org.apache.dubbo.samples 47 | dubbo-spring-boot-sample-api 48 | ${revision} 49 | 50 | 51 | 52 | 53 | org.apache.dubbo 54 | dubbo-dependencies-zookeeper 55 | ${dubbo.version} 56 | pom 57 | 58 | 59 | org.slf4j 60 | slf4j-log4j12 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | org.springframework.boot 71 | spring-boot-maven-plugin 72 | ${spring-boot.version} 73 | 74 | 75 | 76 | repackage 77 | 78 | 79 | 80 | 81 | false 82 | ${project.artifactId}-${spring-boot.version} 83 | ${user.dir}/target 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.demo.consumer.bootstrap; 18 | 19 | import org.apache.dubbo.config.annotation.Reference; 20 | import org.apache.dubbo.spring.boot.demo.consumer.DemoService; 21 | import org.slf4j.Logger; 22 | import org.slf4j.LoggerFactory; 23 | import org.springframework.boot.ApplicationRunner; 24 | import org.springframework.boot.SpringApplication; 25 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 26 | import org.springframework.context.annotation.Bean; 27 | 28 | /** 29 | * Dubbo Registry ZooKeeper Consumer Bootstrap 30 | */ 31 | @EnableAutoConfiguration 32 | public class DubboRegistryZooKeeperConsumerBootstrap { 33 | 34 | private final Logger logger = LoggerFactory.getLogger(getClass()); 35 | 36 | @Reference(version = "${demo.service.version}") 37 | private DemoService demoService; 38 | 39 | public static void main(String[] args) { 40 | SpringApplication.run(DubboRegistryZooKeeperConsumerBootstrap.class).close(); 41 | } 42 | 43 | @Bean 44 | public ApplicationRunner runner() { 45 | return args -> logger.info(demoService.sayHello("mercyblitz")); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /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} 16 | file: ${user.home}/dubbo-cache/${spring.application.name}/dubbo.cache -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | org.apache.dubbo.samples 23 | dubbo-spring-boot-samples 24 | ${revision} 25 | ../pom.xml 26 | 27 | 4.0.0 28 | 29 | dubbo-spring-boot-registry-zookeeper-samples 30 | Apache Dubbo Spring Boot :: Samples : Registry Zookeeper 31 | Apache Dubbo Spring Boot Registry Zookeeper Samples 32 | pom 33 | 34 | 35 | consumer-sample 36 | provider-sample 37 | 38 | 39 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | org.apache.dubbo.samples 23 | dubbo-spring-boot-registry-zookeeper-samples 24 | ${revision} 25 | ../pom.xml 26 | 27 | 4.0.0 28 | 29 | dubbo-spring-boot-registry-zookeeper-provider-sample 30 | Apache Dubbo Spring Boot :: Samples : Registry Zookeeper :: Provider Sample 31 | 32 | 33 | 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter 38 | 39 | 40 | 41 | org.apache.dubbo 42 | dubbo-spring-boot-starter 43 | ${revision} 44 | 45 | 46 | 47 | org.apache.dubbo.samples 48 | dubbo-spring-boot-sample-api 49 | ${revision} 50 | 51 | 52 | 53 | 54 | org.apache.dubbo 55 | dubbo-dependencies-zookeeper 56 | ${dubbo.version} 57 | pom 58 | 59 | 60 | org.slf4j 61 | slf4j-log4j12 62 | 63 | 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 | false 83 | ${project.artifactId}-${spring-boot.version} 84 | ${user.dir}/target 85 | 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.demo.provider.bootstrap; 18 | 19 | import org.apache.dubbo.spring.boot.demo.provider.service.DefaultDemoService; 20 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 21 | import org.springframework.boot.builder.SpringApplicationBuilder; 22 | import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; 23 | import org.springframework.context.ApplicationListener; 24 | import org.springframework.core.env.Environment; 25 | 26 | /** 27 | * Dubbo Registry ZooKeeper Provider Bootstrap 28 | * 29 | * @see DefaultDemoService 30 | * @since 2.7.0 31 | */ 32 | @EnableAutoConfiguration 33 | public class DubboRegistryZooKeeperProviderBootstrap { 34 | 35 | public static void main(String[] args) { 36 | new SpringApplicationBuilder(DubboRegistryZooKeeperProviderBootstrap.class) 37 | .listeners((ApplicationListener) event -> { 38 | Environment environment = event.getEnvironment(); 39 | int port = environment.getProperty("embedded.zookeeper.port", int.class); 40 | new EmbeddedZooKeeper(port, false).start(); 41 | }) 42 | .run(args); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/dubbo-registry-zookeeper-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.demo.provider.service; 18 | 19 | import org.apache.dubbo.config.annotation.Service; 20 | import org.apache.dubbo.spring.boot.demo.consumer.DemoService; 21 | import org.springframework.beans.factory.annotation.Value; 22 | 23 | /** 24 | * Default {@link DemoService} 25 | * 26 | * @see DemoService 27 | * @since 2.7.0 28 | */ 29 | @Service(version = "${demo.service.version}") 30 | public class DefaultDemoService implements DemoService { 31 | 32 | /** 33 | * The default value of ${dubbo.application.name} is ${spring.application.name} 34 | */ 35 | @Value("${dubbo.application.name}") 36 | private String serviceName; 37 | 38 | @Override 39 | public String sayHello(String name) { 40 | return String.format("[%s] : Hello, %s", serviceName, name); 41 | } 42 | } -------------------------------------------------------------------------------- /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 | # Base packages to scan Dubbo Component: @org.apache.dubbo.config.annotation.Service 4 | dubbo.scan.base-packages=org.apache.dubbo.spring.boot.demo.provider.service 5 | 6 | # Dubbo Application 7 | ## The default value of dubbo.application.name is ${spring.application.name} 8 | ## dubbo.application.name=${spring.application.name} 9 | 10 | embedded.zookeeper.port = 2181 11 | 12 | # Dubbo Protocol 13 | dubbo.protocol.name=dubbo 14 | ## Random port 15 | dubbo.protocol.port=-1 16 | 17 | ## Dubbo Registry 18 | dubbo.registry.address=zookeeper://127.0.0.1:${embedded.zookeeper.port} 19 | dubbo.registry.file = ${user.home}/dubbo-cache/${spring.application.name}/dubbo.cache 20 | 21 | ## DemoService version 22 | demo.service.version=1.0.0 -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | org.apache.dubbo.samples 23 | dubbo-spring-boot-externalized-configuration-samples 24 | ${revision} 25 | ../pom.xml 26 | 27 | 4.0.0 28 | 29 | dubbo-spring-boot-externalized-configuration-consumer-sample 30 | Apache Dubbo Spring Boot :: Samples : Externalized Configuration :: Consumer Sample 31 | 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-web 37 | 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-starter-actuator 42 | 43 | 44 | 45 | 46 | org.apache.dubbo 47 | dubbo-spring-boot-starter 48 | ${revision} 49 | 50 | 51 | 52 | org.apache.dubbo 53 | dubbo-spring-boot-actuator 54 | ${revision} 55 | 56 | 57 | 58 | org.apache.dubbo.samples 59 | dubbo-spring-boot-sample-api 60 | ${revision} 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | org.springframework.boot 69 | spring-boot-maven-plugin 70 | ${spring-boot.version} 71 | 72 | 73 | 74 | repackage 75 | 76 | 77 | 78 | 79 | false 80 | ${project.artifactId}-${spring-boot.version} 81 | ${user.dir}/target 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.demo.consumer.bootstrap; 18 | 19 | import org.apache.dubbo.config.annotation.Reference; 20 | import org.apache.dubbo.spring.boot.demo.consumer.DemoService; 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 | import org.springframework.web.bind.annotation.RequestMapping; 29 | import org.springframework.web.bind.annotation.RequestParam; 30 | import org.springframework.web.bind.annotation.RestController; 31 | 32 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 33 | 34 | /** 35 | * Dubbo Externalized Configuration Consumer Bootstrap 36 | */ 37 | @EnableAutoConfiguration 38 | @RestController 39 | public class DubboExternalizedConfigurationConsumerBootstrap { 40 | 41 | private final Logger logger = LoggerFactory.getLogger(getClass()); 42 | 43 | @Reference(version = "${demo.service.version}", url = "${demo.service.url}") 44 | private DemoService demoService; 45 | 46 | public static void main(String[] args) { 47 | SpringApplication.run(DubboExternalizedConfigurationConsumerBootstrap.class); 48 | } 49 | 50 | @RequestMapping(value = "/say-hello", method = GET) 51 | public String sayHello(@RequestParam String name) { 52 | return demoService.sayHello(name); 53 | } 54 | 55 | @Bean 56 | public ApplicationRunner runner() { 57 | return args -> logger.info(demoService.sayHello("mercyblitz")); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /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 | management: 6 | endpoints: 7 | web: 8 | exposure: 9 | include: '*' 10 | endpoint: 11 | dubbo: 12 | enabled: true 13 | dubboshutdown: 14 | enabled: true 15 | dubboconfigs: 16 | enabled: true 17 | dubboservices: 18 | enabled: true 19 | dubboreferences: 20 | enabled: true 21 | dubboproperties: 22 | enabled: true 23 | security: 24 | ## Deprecated 2.x 25 | enabled: false 26 | 27 | ## For Spring Boot 1.x demo 28 | endpoints: 29 | dubbo: 30 | enabled: true 31 | sensitive: false 32 | dubboshutdown: 33 | enabled: true 34 | dubboconfigs: 35 | enabled: true 36 | dubboservices: 37 | enabled: true 38 | dubboreferences: 39 | enabled: true 40 | dubboproperties: 41 | enabled: true 42 | 43 | demo: 44 | service: 45 | version: 1.0.0 46 | url: dubbo://localhost:12345 -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/externalized-configuration-samples/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | org.apache.dubbo.samples 23 | dubbo-spring-boot-samples 24 | ${revision} 25 | ../pom.xml 26 | 27 | 4.0.0 28 | 29 | dubbo-spring-boot-externalized-configuration-samples 30 | Apache Dubbo Spring Boot :: Samples : Externalized Configuration 31 | Apache Dubbo Spring Boot Externalized Configuration Samples 32 | pom 33 | 34 | 35 | consumer-sample 36 | provider-sample 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | org.apache.dubbo.samples 23 | dubbo-spring-boot-externalized-configuration-samples 24 | ${revision} 25 | ../pom.xml 26 | 27 | 4.0.0 28 | 29 | dubbo-spring-boot-externalized-configuration-provider-sample 30 | Apache Dubbo Spring Boot :: Samples : Externalized Configuration :: Provider Sample 31 | 32 | 33 | 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter 38 | 39 | 40 | 41 | org.apache.dubbo 42 | dubbo-spring-boot-starter 43 | ${revision} 44 | 45 | 46 | 47 | org.apache.dubbo.samples 48 | dubbo-spring-boot-sample-api 49 | ${revision} 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | org.springframework.boot 58 | spring-boot-maven-plugin 59 | ${spring-boot.version} 60 | 61 | 62 | 63 | repackage 64 | 65 | 66 | 67 | 68 | false 69 | ${project.artifactId}-${spring-boot.version} 70 | ${user.dir}/target 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.demo.provider.bootstrap; 18 | 19 | import org.apache.dubbo.spring.boot.demo.provider.service.DefaultDemoService; 20 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 21 | import org.springframework.boot.builder.SpringApplicationBuilder; 22 | 23 | /** 24 | * Dubbo Externalized Configuration Provider Bootstrap 25 | * 26 | * @see DefaultDemoService 27 | * @since 2.7.0 28 | */ 29 | @EnableAutoConfiguration 30 | public class DubboExternalizedConfigurationProviderBootstrap { 31 | 32 | public static void main(String[] args) { 33 | new SpringApplicationBuilder(DubboExternalizedConfigurationProviderBootstrap.class) 34 | .run(args); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.demo.provider.service; 18 | 19 | import org.apache.dubbo.config.annotation.Service; 20 | import org.apache.dubbo.spring.boot.demo.consumer.DemoService; 21 | import org.springframework.beans.factory.annotation.Value; 22 | 23 | /** 24 | * Default {@link DemoService} 25 | * 26 | * @see DemoService 27 | * @since 2.7.0 28 | */ 29 | @Service(version = "${demo.service.version}") 30 | public class DefaultDemoService implements DemoService { 31 | 32 | /** 33 | * The default value of ${dubbo.application.name} is ${spring.application.name} 34 | */ 35 | @Value("${dubbo.application.name}") 36 | private String serviceName; 37 | 38 | @Override 39 | public String sayHello(String name) { 40 | return String.format("[%s] : Hello, %s", serviceName, name); 41 | } 42 | } -------------------------------------------------------------------------------- /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 | # Base packages to scan Dubbo Component: @org.apache.dubbo.config.annotation.Service 4 | dubbo.scan.base-packages=org.apache.dubbo.spring.boot.demo.provider.service 5 | 6 | # Dubbo Application 7 | ## The default value of dubbo.application.name is ${spring.application.name} 8 | ## dubbo.application.name=${spring.application.name} 9 | 10 | # Dubbo Protocol 11 | dubbo.protocol.name=dubbo 12 | dubbo.protocol.port=12345 13 | 14 | ## Dubbo Registry 15 | dubbo.registry.address=N/A 16 | 17 | ## DemoService version 18 | demo.service.version=1.0.0 -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | org.apache.dubbo 23 | dubbo-spring-boot-parent 24 | ${revision} 25 | ../dubbo-spring-boot-parent/pom.xml 26 | 27 | 4.0.0 28 | 29 | org.apache.dubbo.samples 30 | dubbo-spring-boot-samples 31 | pom 32 | Apache Dubbo Spring Boot :: Samples 33 | Apache Dubbo Spring Boot :: Samples 34 | 35 | 36 | sample-api 37 | auto-configure-samples 38 | externalized-configuration-samples 39 | dubbo-registry-zookeeper-samples 40 | dubbo-registry-nacos-samples 41 | 42 | 43 | 44 | 45 | 46 | org.apache.maven.plugins 47 | maven-deploy-plugin 48 | 49 | true 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | spring-boot-1.3 60 | 61 | 1.3.8.RELEASE 62 | 63 | 64 | 65 | 66 | 67 | spring-boot-1.4 68 | 69 | 1.4.7.RELEASE 70 | 71 | 72 | 73 | 74 | 75 | spring-boot-1.5 76 | 77 | 1.5.21.RELEASE 78 | 79 | 80 | 81 | 82 | 83 | spring-boot-2.0 84 | 85 | 2.0.9.RELEASE 86 | 87 | 88 | 89 | 90 | 91 | spring-boot-2.1 92 | 93 | 2.1.9.RELEASE 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/sample-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | org.apache.dubbo.samples 23 | dubbo-spring-boot-samples 24 | ${revision} 25 | ../pom.xml 26 | 27 | 4.0.0 28 | 29 | dubbo-spring-boot-sample-api 30 | Apache Dubbo Spring Boot :: Samples : API 31 | 32 | -------------------------------------------------------------------------------- /dubbo-spring-boot-samples/sample-api/src/main/java/org/apache/dubbo/spring/boot/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 org.apache.dubbo.spring.boot.demo.consumer; 18 | 19 | /** 20 | * Demo Service interface 21 | * 22 | * @since 2.7.0 23 | */ 24 | public interface DemoService { 25 | 26 | String sayHello(String name); 27 | 28 | } -------------------------------------------------------------------------------- /dubbo-spring-boot-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 22 | org.apache.dubbo 23 | dubbo-spring-boot-parent 24 | ${revision} 25 | ../dubbo-spring-boot-parent 26 | 27 | 4.0.0 28 | 29 | dubbo-spring-boot-starter 30 | jar 31 | Apache Dubbo Spring Boot :: Starter 32 | Apache Dubbo Spring Boot Starter 33 | 34 | 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter 40 | true 41 | 42 | 43 | 44 | org.apache.dubbo 45 | dubbo-spring-boot-autoconfigure 46 | ${revision} 47 | 48 | 49 | 50 | --------------------------------------------------------------------------------