springconfig配置
2020-05-05 12:18
621 查看
一、配置类服务器的搭建
1.登录github.com,创建一个自己的账号和仓库,并获取仓库地址: debugggcloud_config_demo
转存失败重新上传取消
2.从本地上传一个yml文件上去,内容如下
[code]spring: profiles: active: - dev --- spring: profiles: dev #开发环境 application: name: debugggcloud-config-debuggg-dev --- spring: profiles: test #测试环境 application: name: debugggcloud-config-debuggg-test # 请保存为UTF-8格式
3.创建一个配置类module: debugggcloud_config_3344
转存失败重新上传取消
4.pom的复制
这里最重要的包是
[code] <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency>
全部内容如下
[code]<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>debugggcloud</artifactId> <groupId>com.deubggg</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>debugggcloud_config_3344</artifactId> <dependencies> <!-- springCloud Config --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> <!-- 图形化监控 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!-- 熔断 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</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-jetty</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> </dependency> <!-- 热部署插件 --> <dependency> <groupId>org.springframework</groupId> <artifactId>springloaded</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency> </dependencies> </project>
5.yml内容如下:
[code]server: port: 3344 spring: application: name: debugggcloud-config cloud: config: server: git: uri: https://github.com/mx342/debugggcloud_demo_config.git username: username #账号 password: password #密码
6.启动类创建,并添加注解:@EnableConfigServer
[code]package com.debuggg.cloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.config.server.EnableConfigServer; @SpringBootApplication @EnableConfigServer public class ConfigServer3344 { public static void main(String[] args) { SpringApplication.run(ConfigServer3344.class,args); } }
7.启动,并测试:
效果如下图:
转存失败重新上传取消
二、远程配置应用到具体的服务的搭建
1.将如下配置文件上传到上面创建的git仓库里面去
[code]spring: profiles: active: - dev --- server: port: 7001 #注册中心占用7001端口,冒号后面必须要有空格 spring: profiles: dev application: name: debugggcloud-config-eureka-client eureka: instance: hostname: eureka7001.com #冒号后面必须要有空格 client: register-with-eureka: false #当前的eureka-server自己不注册进服务列表中 fetch-registry: false #不通过eureka获取注册信息 service-url: defaultZone: http://eureka7001.com:7001/eureka/ --- server: port: 7001 #注册中心占用7001端口,冒号后面必须要有空格 spring: profiles: test application: name: debugggcloud-config-eureka-client eureka: instance: hostname: eureka7001.com #冒号后面必须要有空格 client: register-with-eureka: false #当前的eureka-server自己不注册进服务列表中 fetch-registry: false #不通过eureka获取注册信息 service-url: defaultZone: http://eureka7001.com:7001/eureka/
2.将之前的eureka项目中添加一个pom坐标:
[code] <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency>
3.创建一个bootstrap.yml(bootstrap的优先级比application还要高)
具体内容如下:
[code] spring: cloud: config: name: debugggcloud_config_client #需要从github上读取的资源名称,注意没有yml后缀名 profile: test #本次访问的配置项 label: master uri: http://config-3344.com:3344 #本微服务启动后先去找3344号服务,通过SpringCloudConfig获取GitHub的服务地址
烤火的猫 原创文章 36获赞 0访问量 722 关注 私信
相关文章推荐
- SSL/TLS服务器配置
- git配置
- Windows下Maven的安装与配置
- CentOS7下Chrome以及chromedriver的安装配置
- [RHEL] 配置 LVM 卷
- Zabbix(一):server,agent端 安装配置及主机,监控项,触发器,动作,媒介配置步骤
- Java数据持久层框架 MyBatis之API学习三(XML 映射配置文件)
- JNDI学习总结(三)——Tomcat下使用Druid配置JNDI数据源
- Spring中依赖注入的使用和配置
- cors跨域 web.config配置
- Nginx 配置反向代理
- Log4J日志配置详解
- 如何使用NotePad++配置Java编译
- mac 下PHP环境搭建与配置
- Node.js 教程 01 - 简介、安装及配置
- Hibernate关联关系配置(一对一,一对多,多对多)
- 配置 php-fpm
- VNC Viewer Client 和 VNC Server配置
- Linux版迅雷(Xware)安装配置方法
- 01Hibernate配置环境