SpringCloudConfig和Github加载与读取
作者:互联网
<?xml version="1.0" encoding="UTF-8"?> <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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.msb</groupId> <artifactId>spring-cloud-config</artifactId> <version>0.0.1-SNAPSHOT</version> <name>spring-cloud-config</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <spring-boot.version>2.3.7.RELEASE</spring-boot.version> <spring-cloud.version>Hoxton.SR9</spring-cloud.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${spring-boot.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.3.7.RELEASE</version> <configuration> <mainClass>com.msb.SpringCloudConfigApplication</mainClass> </configuration> <executions> <execution> <id>repackage</id> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
@SpringBootApplication @EnableDiscoveryClient @EnableConfigServer public class SpringCloudConfigApplication { public static void main(String[] args) { SpringApplication.run(SpringCloudConfigApplication.class, args); } }
spring: application: name: spring-cloud-config cloud: config: server: git: uri: https://github.com/lcccher/Spring-cloud-config.git label: dev eureka: client: service-url: defaultZone: http://localhost:7900/eureka/ server: port: 9090
---------------------------------------------------------------------------------------------
@RestController public class TestController { @Value("${name}") String name; @GetMapping public String getName(){ return name; } }
配置一定要改成bootstrap 格式 要先加载这个配置文件 再去读取 该文件相当于 拉取了server 端的config server 端的config 是拉取了github上面的配置文件
spring: application: name: spring-cloud-config-client cloud: config: label: test uri: http://localhost:9090/ profile: test eureka: client: service-url: defaultZone: http://localhost:7900/eureka/ server: port: 9091
https://blog.csdn.net/qq_43792385/article/details/104700128
标签:Github,spring,boot,springframework,SpringCloudConfig,org,config,cloud,加载 来源: https://www.cnblogs.com/Lcch/p/16217167.html