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 |
--------------------------------------------------------------------------------