diff --git a/examples/apollo-example/README.md b/examples/apollo-example/README.md new file mode 100644 index 0000000..f73f756 --- /dev/null +++ b/examples/apollo-example/README.md @@ -0,0 +1,28 @@ +## Apollo Client Demo +使用 Apollo Starter 接入配置中心的 demo +


+ +### 模块引入方式 +首先要在POM中引入parent包 +``` + + com.chinaunicom.ebtp + mall-ebtp-cloud-parent + 0.0.1 + +``` +之后在依赖项中添加如下内容: +``` + + com.chinaunicom.ebtp + mall-ebtp-cloud-apollo-starter + +``` + +### 虚拟机参数 +目前要接入胜智云apollo配置中心,需要配置JVM虚拟机参数 +-Denv=DEV +-Dapollo.configService=http://192.168.40.17:9228 + +### 胜智云apollo配置中心 +Apollo控制台在胜智云平台地址是http://192.168.40.17:16464,管理员账号为apollo/admin。 diff --git a/examples/apollo-example/pom.xml b/examples/apollo-example/pom.xml new file mode 100644 index 0000000..8e56f16 --- /dev/null +++ b/examples/apollo-example/pom.xml @@ -0,0 +1,37 @@ + + 4.0.0 + + com.chinaunicom.ebtp + mall-ebtp-cloud-parent + 0.0.1 + + + com.chinaunicom.mall.ebtp.cloud + apollo-example + 0.0.1-SNAPSHOT + jar + + apollo-example + + + UTF-8 + + + + + com.chinaunicom.ebtp + mall-ebtp-cloud-apollo-starter + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/examples/apollo-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/apollo/example/ApolloExampleApplication.java b/examples/apollo-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/apollo/example/ApolloExampleApplication.java new file mode 100644 index 0000000..93e5216 --- /dev/null +++ b/examples/apollo-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/apollo/example/ApolloExampleApplication.java @@ -0,0 +1,14 @@ +package com.chinaunicom.mall.ebtp.cloud.apollo.example; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig; + +@EnableApolloConfig +@SpringBootApplication +public class ApolloExampleApplication { + public static void main(String[] args) { + SpringApplication.run(ApolloExampleApplication.class, args); + } +} diff --git a/examples/apollo-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/apollo/example/controller/ApolloExampleController.java b/examples/apollo-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/apollo/example/controller/ApolloExampleController.java new file mode 100644 index 0000000..0b32e61 --- /dev/null +++ b/examples/apollo-example/src/main/java/com/chinaunicom/mall/ebtp/cloud/apollo/example/controller/ApolloExampleController.java @@ -0,0 +1,18 @@ +package com.chinaunicom.mall.ebtp.cloud.apollo.example.controller; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/apollo") +public class ApolloExampleController { + + private @Value("${example.apollo.message:not found message}") String message; + + @RequestMapping("/message") + public String message() { + return message; + } + +} diff --git a/examples/apollo-example/src/main/resources/application-dev.yml b/examples/apollo-example/src/main/resources/application-dev.yml new file mode 100644 index 0000000..f77630b --- /dev/null +++ b/examples/apollo-example/src/main/resources/application-dev.yml @@ -0,0 +1,16 @@ +server: + port: 8762 + max-http-header-size: 1000000 + +app: + id: mall-ebtp-cloud-demo + +example: + apollo: + message: default + +# Apollo 配置信息 (以下为starter默认配置信息) +# apollo.meta=http://106.74.154.90:9228/ +# apollo.bootstrap.namespace=application +# apollo.bootstrap.enabled=true +# apollo.bootstrap.eagerLoad.enabled=true \ No newline at end of file diff --git a/examples/apollo-example/src/main/resources/application.yml b/examples/apollo-example/src/main/resources/application.yml new file mode 100644 index 0000000..caf4dfc --- /dev/null +++ b/examples/apollo-example/src/main/resources/application.yml @@ -0,0 +1,3 @@ +spring: + profiles: + active: dev \ No newline at end of file diff --git a/examples/apollo-example/src/test/java/com/chinaunicom/mall/ebtp/cloud/apollo/example/AppTest.java b/examples/apollo-example/src/test/java/com/chinaunicom/mall/ebtp/cloud/apollo/example/AppTest.java new file mode 100644 index 0000000..6ab183b --- /dev/null +++ b/examples/apollo-example/src/test/java/com/chinaunicom/mall/ebtp/cloud/apollo/example/AppTest.java @@ -0,0 +1,38 @@ +package com.chinaunicom.mall.ebtp.cloud.apollo.example; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/examples/apollo-example/胜智云平台apollo使用.docx b/examples/apollo-example/胜智云平台apollo使用.docx new file mode 100644 index 0000000..254bc6b Binary files /dev/null and b/examples/apollo-example/胜智云平台apollo使用.docx differ diff --git a/examples/eureka-example/pom.xml b/examples/eureka-example/pom.xml index ddce932..dede508 100644 --- a/examples/eureka-example/pom.xml +++ b/examples/eureka-example/pom.xml @@ -14,7 +14,6 @@ jar eureka-example - http://maven.apache.org UTF-8 @@ -26,4 +25,13 @@ mall-ebtp-cloud-eureka-starter + + + + + org.springframework.boot + spring-boot-maven-plugin + + + diff --git a/examples/eureka-example/src/main/resources/application-dev.yml b/examples/eureka-example/src/main/resources/application-dev.yml new file mode 100644 index 0000000..ea2790d --- /dev/null +++ b/examples/eureka-example/src/main/resources/application-dev.yml @@ -0,0 +1,8 @@ +server: + port: 8082 + max-http-header-size: 1000000 + +# 胜智云eureka 统一配置 (以下内容已在starter中配置好,如无必要无需定义) +# eureka.client.service-url.defaultZone=http://192.168.40.17:12093/eureka/,http://192.168.40.17:18126/eureka/,http://192.168.40.17:28641/eureka/ +# eureka.instance.prefer-ip-address=true +# eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port} \ No newline at end of file diff --git a/examples/eureka-example/src/main/resources/application.yml b/examples/eureka-example/src/main/resources/application.yml index 3385765..01febc7 100644 --- a/examples/eureka-example/src/main/resources/application.yml +++ b/examples/eureka-example/src/main/resources/application.yml @@ -1,12 +1,5 @@ -server: - port: 8082 - max-http-header-size: 1000000 - spring: application: name: eureka-example - -# 胜智云eureka 统一配置 (以下内容已在starter中配置好,如无必要无需定义) -# eureka.client.service-url.defaultZone=http://192.168.40.17:12093/eureka/,http://192.168.40.17:18126/eureka/,http://192.168.40.17:28641/eureka/ -# eureka.instance.prefer-ip-address=true -# eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port} \ No newline at end of file + profiles: + active: dev \ No newline at end of file diff --git a/mall-ebtp-cloud-apollo-starter/pom.xml b/mall-ebtp-cloud-apollo-starter/pom.xml index 6acb98f..4b4bf36 100644 --- a/mall-ebtp-cloud-apollo-starter/pom.xml +++ b/mall-ebtp-cloud-apollo-starter/pom.xml @@ -32,5 +32,9 @@ com.ctrip.framework.apollo apollo-client + + com.chinaunicom.ebtp + mall-ebtp-cloud-mvc-starter +