1. 增加了apollo 配置中心使用的 demo

2. 调整了apollo starter的pom, 增加了对于mvc starter的依赖
This commit is contained in:
Administrator
2020-10-29 10:47:42 +08:00
parent b9a0dd86f4
commit 4518c665f9
12 changed files with 177 additions and 10 deletions

View File

@ -0,0 +1,28 @@
## Apollo Client Demo
使用 Apollo Starter 接入配置中心的 demo
</br></br></br>
### 模块引入方式
首先要在POM中引入parent包
```
<parent>
<groupId>com.chinaunicom.ebtp</groupId>
<artifactId>mall-ebtp-cloud-parent</artifactId>
<version>0.0.1</version>
</parent>
```
之后在依赖项中添加如下内容:
```
<dependency>
<groupId>com.chinaunicom.ebtp</groupId>
<artifactId>mall-ebtp-cloud-apollo-starter</artifactId>
</dependency>
```
### 虚拟机参数
目前要接入胜智云apollo配置中心需要配置JVM虚拟机参数
-Denv=DEV
-Dapollo.configService=http://192.168.40.17:9228
### 胜智云apollo配置中心
Apollo控制台在胜智云平台地址是http://192.168.40.17:16464管理员账号为apollo/admin。

View File

@ -0,0 +1,37 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.chinaunicom.ebtp</groupId>
<artifactId>mall-ebtp-cloud-parent</artifactId>
<version>0.0.1</version>
</parent>
<groupId>com.chinaunicom.mall.ebtp.cloud</groupId>
<artifactId>apollo-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>apollo-example</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.chinaunicom.ebtp</groupId>
<artifactId>mall-ebtp-cloud-apollo-starter</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

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

View File

@ -0,0 +1,3 @@
spring:
profiles:
active: dev

View File

@ -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 );
}
}

View File

@ -14,7 +14,6 @@
<packaging>jar</packaging> <packaging>jar</packaging>
<name>eureka-example</name> <name>eureka-example</name>
<url>http://maven.apache.org</url>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -26,4 +25,13 @@
<artifactId>mall-ebtp-cloud-eureka-starter</artifactId> <artifactId>mall-ebtp-cloud-eureka-starter</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project> </project>

View File

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

View File

@ -1,12 +1,5 @@
server:
port: 8082
max-http-header-size: 1000000
spring: spring:
application: application:
name: eureka-example name: eureka-example
profiles:
# 胜智云eureka 统一配置 (以下内容已在starter中配置好如无必要无需定义) active: dev
# 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}

View File

@ -32,5 +32,9 @@
<groupId>com.ctrip.framework.apollo</groupId> <groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId> <artifactId>apollo-client</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.chinaunicom.ebtp</groupId>
<artifactId>mall-ebtp-cloud-mvc-starter</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>