配置中心
【摘要】 前言本文介绍如何建立配置中心,服务器;操作步骤使用idea新建立工程com.nick.client,依赖配置加入cloud discovery -> eureka discoveryweb -> webcloud config -> config serverClientApplication类添加注解@EnableDiscoveryClient与@EnableConfigServer@Sp...
前言
本文介绍如何建立配置中心,服务器;
操作步骤
使用idea新建立工程com.nick.client,依赖配置加入
cloud discovery -> eureka discovery
web -> web
cloud config -> config server
ClientApplication类添加注解
@EnableDiscoveryClient
与@EnableConfigServer
@SpringBootApplication@EnableDiscoveryClient@EnableConfigServerpublic class ConfigApplication { public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}
spring:
application:
name: order # 这里数据库一般在生产环境上不同服务
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 123456
url: jdbc:mysql://127.0.0.1/diancan?characterEncoding=utf-8&useSSL=false
jpa:
show-sql: trueeureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/#-Dserver.port=8081#server:# port: 8081
修改application.properties为application.yml
spring:
application:
name: config
cloud:
config:
server:
git:
uri: https://github.com/qiujiahong/config-repo
username:
password:
search-paths: order default-label: master
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
启动项目,访问尝试http://localhost:8080/order/order.yml ,http请求地址和资源文件映射如下:
/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties
踩坑
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)