Skip to content

Commit

Permalink
0.1.x (#364)
Browse files Browse the repository at this point in the history
* Bug fix on test case

* Polish #327 & #325

* Polish #321

* Polish #220 no program

* Switch Yaml file

* Update version to be 0.2.0

* Polish #218

* Update Documents

* Fix the test case's bugs

* Fix plugins' issues

* Fix test-cases

* Fix test cases

* Fixes an issue on DubboMvcEndpoint

* Polish: Fix a relaxed property name issue

* Optimize Awaiting implementation

* Remove author from JavaDoc

* Refactor

* Merge

* Update dependencies and implementations

* Update Samples

* Fix the test cases
  • Loading branch information
mercyblitz committed Jan 8, 2019
1 parent a5b15d7 commit e99a9f5
Show file tree
Hide file tree
Showing 45 changed files with 1,535 additions and 200 deletions.
3 changes: 1 addition & 2 deletions dubbo-spring-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
<parent>
<groupId>com.alibaba.boot</groupId>
<artifactId>dubbo-spring-boot-parent</artifactId>

<version>0.1.2-SNAPSHOT</version>
<relativePath>../dubbo-spring-boot-parent</relativePath>
<relativePath>../dubbo-spring-boot-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ public class DubboDefaultPropertiesEnvironmentPostProcessor implements Environme
*/
private static final String DUBBO_APPLICATION_NAME_PROPERTY = "dubbo.application.name";

/**
* The property name of {@link EnableDubboConfig#multiple() @EnableDubboConfig.multiple()}
*/
private static final String DUBBO_CONFIG_MULTIPLE_PROPERTY = "dubbo.config.multiple";

/**
* The property name of {@link ApplicationConfig#getQosEnable() application's QOS enable}
*/
private static final String DUBBO_APPLICATION_QOS_ENABLE_PROPERTY = "dubbo.application.qos-enable";

@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
MutablePropertySources propertySources = environment.getPropertySources();
Expand All @@ -81,6 +91,8 @@ public int getOrder() {
private Map<String, Object> createDefaultProperties(ConfigurableEnvironment environment) {
Map<String, Object> defaultProperties = new HashMap<String, Object>();
setDubboApplicationNameProperty(environment, defaultProperties);
setDubboConfigMultipleProperty(defaultProperties);
setDubboApplicationQosEnableProperty(defaultProperties);
return defaultProperties;
}

Expand All @@ -92,6 +104,14 @@ private void setDubboApplicationNameProperty(Environment environment, Map<String
}
}

private void setDubboConfigMultipleProperty(Map<String, Object> defaultProperties) {
defaultProperties.put(DUBBO_CONFIG_MULTIPLE_PROPERTY, Boolean.TRUE.toString());
}

private void setDubboApplicationQosEnableProperty(Map<String, Object> defaultProperties) {
defaultProperties.put(DUBBO_APPLICATION_QOS_ENABLE_PROPERTY, Boolean.FALSE.toString());
}

/**
* Copy from BusEnvironmentPostProcessor#addOrReplace(MutablePropertySources, Map)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
/**
* {@link DubboAutoConfiguration} Test On multiple Dubbo Configuration
*
* @author <a href="mailto:[email protected]">Mercy</a>
* @since 1.0.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
Expand Down Expand Up @@ -152,7 +153,7 @@ public class DubboAutoConfigurationOnMultipleConfigTest {
public void testMultipleDubboConfigBindingProperties() {


Assert.assertEquals(2, applications.size());
Assert.assertEquals(3, applications.size());

Assert.assertEquals(1, modules.size());

Expand All @@ -176,7 +177,7 @@ public void testApplicationContext() {
*/
Map<String, ApplicationConfig> applications = beansOfTypeIncludingAncestors(applicationContext, ApplicationConfig.class);

Assert.assertEquals(2, applications.size());
Assert.assertEquals(3, applications.size());

/**
* Multiple {@link ModuleConfig}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void testConsumerConfig() {

@Test
public void testMultipleDubboConfigConfiguration() {
Assert.assertNull(multipleDubboConfigConfiguration);
Assert.assertNotNull(multipleDubboConfigConfiguration);
}

@Test
Expand All @@ -160,7 +160,7 @@ public void testSingleDubboConfigConfiguration() {

@Test
public void testServiceAnnotationBeanPostProcessor() {
Assert.assertNull(multipleDubboConfigConfiguration);
Assert.assertNotNull(multipleDubboConfigConfiguration);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public void testPostProcessEnvironment() {
MutablePropertySources propertySources = environment.getPropertySources();
// Nothing to change
PropertySource defaultPropertySource = propertySources.get("defaultProperties");
Assert.assertNull(defaultPropertySource);
Assert.assertNotNull(defaultPropertySource);
Assert.assertEquals("true", defaultPropertySource.getProperty("dubbo.config.multiple"));
Assert.assertEquals("false", defaultPropertySource.getProperty("dubbo.application.qos-enable"));

// Case 2 : Only set property "spring.application.name"
environment.setProperty("spring.application.name", "demo-dubbo-application");
Expand All @@ -67,7 +69,7 @@ public void testPostProcessEnvironment() {
environment.setProperty("dubbo.application.name", "demo-dubbo-application");
instance.postProcessEnvironment(environment, springApplication);
defaultPropertySource = propertySources.get("defaultProperties");
Assert.assertNull(defaultPropertySource);
Assert.assertNotNull(defaultPropertySource);
dubboApplicationName = environment.getProperty("dubbo.application.name");
Assert.assertEquals("demo-dubbo-application", dubboApplicationName);

Expand All @@ -81,5 +83,15 @@ public void testPostProcessEnvironment() {
defaultPropertySource = propertySources.get("defaultProperties");
dubboApplicationName = defaultPropertySource.getProperty("dubbo.application.name");
Assert.assertEquals("demo-dubbo-application", dubboApplicationName);

// Case 5 : Rest dubbo.config.multiple and dubbo.application.qos-enable
environment = new MockEnvironment();
propertySources = environment.getPropertySources();
propertySources.addLast(new MapPropertySource("defaultProperties", new HashMap<String, Object>()));
environment.setProperty("dubbo.config.multiple", "false");
environment.setProperty("dubbo.application.qos-enable", "true");
instance.postProcessEnvironment(environment, springApplication);
Assert.assertEquals("false", environment.getProperty("dubbo.config.multiple"));
Assert.assertEquals("true", environment.getProperty("dubbo.application.qos-enable"));
}
}
}
69 changes: 19 additions & 50 deletions dubbo-spring-boot-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,8 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>1.5.18.RELEASE</spring-boot.version>
<dubbo.version>2.6.5</dubbo.version>
<zkclient.version>0.2</zkclient.version>
<zookeeper.version>3.4.9</zookeeper.version>
<curator-framework.version>2.12.0</curator-framework.version>
<alibaba-spring-context-support.version>1.0.2</alibaba-spring-context-support.version>

<dubbo-registry-nacos.version>0.0.2</dubbo-registry-nacos.version>
<nacos-client.version>0.6.2</nacos-client.version>
<!-- Build args -->
<argline>-server -Xms256m -Xmx512m -XX:PermSize=64m -XX:MaxPermSize=128m -Dfile.encoding=UTF-8
-Djava.net.preferIPv4Stack=true
Expand All @@ -63,7 +60,6 @@

<dependencyManagement>
<dependencies>

<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -73,6 +69,15 @@
<scope>import</scope>
</dependency>

<!-- Dubbo dependencies -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-dependencies-bom</artifactId>
<version>${dubbo.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<!-- Dubbo -->
<dependency>
<groupId>com.alibaba</groupId>
Expand All @@ -94,54 +99,18 @@
</exclusions>
</dependency>

<!-- Alibaba Spring Context extension -->
<dependency>
<groupId>com.alibaba.spring</groupId>
<artifactId>spring-context-support</artifactId>
<version>${alibaba-spring-context-support.version}</version>
</dependency>

<!-- ZK -->
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>${zookeeper.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- Dubbo Nacos registry dependency -->
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>${zkclient.version}</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>log4j</artifactId>
<groupId>log4j</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-registry-nacos</artifactId>
<version>${dubbo-registry-nacos.version}</version>
</dependency>

<!-- Keep latest Nacos client version -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>${curator-framework.version}</version>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>${nacos-client.version}</version>
</dependency>

</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.alibaba.boot.samples</groupId>
<artifactId>dubbo-spring-boot-auto-configure-samples</artifactId>
<version>0.1.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>dubbo-spring-boot-auto-configure-consumer-sample</artifactId>
<name>Dubbo Spring Boot Samples : Auto-Configure :: Consumer Sample</name>
<dependencies>

<!-- Spring Boot dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>dubbo-spring-boot-sample-api</artifactId>
<version>${project.version}</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.boot.dubbo.demo.consumer.bootstrap;

import com.alibaba.boot.dubbo.demo.consumer.DemoService;
import com.alibaba.dubbo.config.annotation.Reference;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;

/**
* Dubbo Auto Configuration Consumer Bootstrap
*
* @since 1.0.0
*/
@EnableAutoConfiguration
public class DubboAutoConfigurationConsumerBootstrap {

private final Logger logger = LoggerFactory.getLogger(getClass());

@Reference(version = "1.0.0", url = "dubbo://localhost:12345")
private DemoService demoService;

@Bean
public ApplicationRunner runner() {
return new ApplicationRunner() {
@Override
public void run(ApplicationArguments args) throws Exception {
logger.info(demoService.sayHello("mercyblitz"));
}
};
}

public static void main(String[] args) {
SpringApplication.run(DubboAutoConfigurationConsumerBootstrap.class).close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
spring:
application:
name: dubbo-auto-configure-consumer-sample
Loading

0 comments on commit e99a9f5

Please sign in to comment.