配置Config-server
1.引入相应的依赖包
<dependencies>
<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>
</dependency>
<!-- 监控的依赖必须引入-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
2.application.yml配置文件
server:
port: 8889
spring:
application:
name: shdp-config-server
profiles:
active: native #配置本地配置文件必须激活内置的native,如若还需激活其他的就配置多个,如:native,dev
cloud:
config:
server:
# git:
# uri: https://github.com/chinoukin/SpringcloudConfig
# native为本地配置
native:
search-locations: classpath:/config,classpath:/config/datasource,classpath:/config/cmn,classpath:/config/redis,classpath:/config/eureka-client
bootstrap: true
management:
server:
port: 8889
endpoints:
web:
exposure:
include: "*"
3.目录结构展示
配置Config-client
1.引入相应的依赖包
<dependencies>
<!-- eureka client非必须-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
2.bootstrap.yml 配置文件(一定得是bootstrap.yml)
spring:
cloud:
config:
uri: http://127.0.0.1:8889/
name: cmn,ds,redis,eureka-client
profile: dev
discovery:
enabled: true
service-id: config-server
# euraka可根据实际情况选择, uri与eureka discovery选择一种即可
eureka:
client:
serviceUrl:
defaultZone: http://127.0.0.1:2105/eureka/
instance:
preferIpAddress: true
instance-id: ${spring.cloud.client.ip-address}:${server.port} # 地址格式=ip:端口