2018-09-06 17:18:20.0|分类: spring cloud|浏览量: 2535
官网:http://cloud.spring.io/spring-cloud-config/ https://springcloud.cc/spring-cloud-config.html 注册码云账号https://gitee.com 创建项目,并且创建测试配置文件app.properties、app-dev.properties、app-test.properties spring cloud server项目结构 ConfigServerApp.java package com.cookqq.config.server; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.config.server.EnableConfigServer; /** * config server */ @SpringBootApplication @EnableConfigServer public class ConfigServerApp { public static void main( String[] args ) { SpringApplication.run(ConfigServerApp.class, args); } } application.yml server: port: 8880 spring: application: name: config-server cloud: config: server: git: uri: https://gitee.com/bugeasy/spring-cloud-config username: xxx@qq.com password: xxxx logging: level: org.springframework.cloud: DEBUG org.springframework.boot: DEBUG pom.xml <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> <groupId>com.cookqq</groupId> <artifactId>config-server</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>config-server</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.1</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <!-- 引入spring cloud的依赖 --> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Edgware.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project> 插件spring-boot-maven-plugin用于mvn install打包jar文件,如果不设置repackage,mvn install打包之后只有简单的代码,没有spring cloud的依赖代码 ubuntu环境运行jar HTTP服务具有以下格式的资源: /{application}/{profile}[/{label}] /{application}-{profile}.yml /{label}/{application}-{profile}.yml /{application}-{profile}.properties /{label}/{application}-{profile}.properties {application}表示微服务的名称 {label}表示git仓库分支,默认是master 访问浏览器http://192.168.99.100:8880/app/dev http://192.168.99.100:8880/app/dev/master 返回结果: { http://192.168.99.100:8880/app-dev.properties |