为配置和您的应用程序创建一个应用程序
@SpringBootApplication
@EnableConfigServer
public class ConfigApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(ConfigApplication.class, args);
}
}
配置服务器中的application.yml
spring:
cloud:
config:
server:
native:
search-locations: classpath:/shared
profiles:
active: native
security:
user:
password: pass
server:
port: 8888
并像这样在 src/main/resources/shared 和 your-service.yml 中创建共享文件夹
spring:
security:
basic:
enabled: false
server:
port: 8083
配置服务器中的maven pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<finalName>config</finalName>
</configuration>
</plugin>
</plugins>
</build>
在你的服务spring boot应用中添加/src/main/resources/bootstrap.yml
喜欢这个
spring:
application:
name: your-service
cloud:
config:
uri: http://localhost:8888
fail-fast: true
username: user
password: pass
并将此依赖项添加到您的服务中
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
首先运行配置服务器,然后运行你的 spring boot 服务