SpringCloud_Config
配置中心,提供本地、git、svn等配置仓库;
连接rabbitmq实现客户端动态刷新配置。
依赖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>
<parent>
<groupId>org.pingruan</groupId>
<artifactId>vander-framework-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>org.pingruan.springboot</groupId>
<artifactId>vander-config-center</artifactId>
<dependencies>
<!-- 服务监控 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- 配置中心动态刷新配置,需要配置rabbitmq -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<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>
<!-- 默认GIT,如果需要使用svn -->
<!-- <dependency> <groupId>org.tmatesoft.svnkit</groupId> <artifactId>svnkit</artifactId>
</dependency> -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
配置文件bootstrap.yml
server:
port: 9002
spring:
#------------配置中心方式二 本地------------------
application:
name: vander-config-center
security: # 设置配置中心安全访问
user:
name: root
password: 123456
profiles:
active: native # 使用本地配置文件
cloud:
config:
server:
native:
search-locations: classpath:config/{profile} # 本地配置文件目录
# searchLocations: file:/d:/configs/{profile}
#------------配置中心方式一 git------------------
# application:
# name: vander-config-center
# security: # 设置配置中心安全访问
# user:
# name: root
# password: 123456
# cloud:
# config:
# #仓库的分支
# label: master
# server:
# git:
# # 默认将存储在系统临时目录 需要有系统访问权限
# # basedir: tmp/
# #git仓库地址
# uri: https://gitee.com/pingruan/springboot-config-file-center.git
# #仓库路径
# search-paths: springcloud
# #访问git仓库的用户名
# username:
# #访问git仓库的用户密码 如果Git仓库为公开仓库,可以不填写用户名和密码,如果是私有仓库需要填写
# password:
#-----------------配置rabbitmq实现配置文件同步 更新git配置,再在客户端post触发钩子---------------------------
rabbitmq:
host: 192.168.164.100
port: 5672
username: root
password: qwe123
#------------springboot-admin开启监控------------------
management:
endpoints:
web:
exposure:
include:
- "*"
endpoint:
health:
show-details: always
#------------注册中心配置------------------
eureka:
client:
registerWithEureka: true #服务注册开关
fetchRegistry: true #服务发现开关
serviceUrl: #Eureka客户端与Eureka服务端进行交互的地址,多个中间用逗号分隔
defaultZone: http://root:qwe123@server1:9001/eureka/
instance:
prefer-ip-address: true #将自己的ip地址注册到Eureka服务中
ip-address: ${IP_ADDRESS:127.0.0.1}
instance-id: ${spring.application.name}:${server.port} #指定实例id
metadata-map:
user.name: ${spring.security.user.name} # 配置访问权限
user.password: ${spring.security.user.password} #
配置源码
/**
* 配置中心
*
* @author vander
*
*/
@EnableConfigServer
@EnableDiscoveryClient
@SpringBootApplication
public class SpringBootConfigCenter {
public static void main(String[] args) {
SpringApplication.run(SpringBootConfigCenter.class, args);
}
}