springboot+springcloud config
参考:sorry,全找不到了,当时没记录,最后后知后觉觉得应该记录,所以后面的都有在asfood父项目中的doc文件夹下记录,望见谅。
1. springconfig server
1.1. pom.xml
<!-- 父项目以来 --> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
1.2 启动类
@EnableConfigServer
@SpringBootApplication
public class TomatoApplication {
public static void main(String[] args) {
SpringApplication.run(TomatoApplication.class, args);
}
}
1.3 配置
server:
port: 55590
spring:
application:
name: asfood-tomato
profiles:
active: dev
cloud:
config:
server:
git:
# 配置git仓库的地址 #访问地址: http://localhost:55590/{filename}/{env}/{branch}
uri: https://github.com/molyjao/mlims
# git仓库地址下的相对地址,可以配置多个,用,分割。
#search-paths: asfoodconfig
# git仓库的账号
#username: #jiu_shaan@163.com
# git仓库的密码
#password: #配置之后访问git配置需要输入用户名密码
security:
user:
name: tomato
password: tomato
启动工程,如果可以使用 http://localhost:55590/{文件名不带后面环境}/{环境}/{git分支}访问 ,并可以展示里面内容即可。
2. springcloud client
2.1 pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</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> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
2.2 启动类
@SpringBootApplication
public class KetchupApplication {
public static void main(String[] args) {
SpringApplication.run(KetchupApplication.class, args);
}
}
控制层:
@RestController
@RefreshScope //刷新配置使用的注解,
public class KetchupController { //qqname为配置文件的内容的一个key,':'后面是默认值
@Value("${qqname:defaultqqname}")
private String str; @RequestMapping("/ketchup")
String hello() {
return "Hello " + str + "!";
}
}
2.3 配置文件:两部分bootstrap.yml和application.yml文件,由于bootstrap.yml加载最早,所以需要加载服务端配置文件内的内容需要优先加载。
bootstrap.yml
spring:
cloud:
config:
name: asfood
profile: dev
label: master
uri: http://localhost:55590/
#discovery:
enabled: true # 默认false,设为true表示使用注册中心中的configserver配置而不自己配置configserver的uri
serviceId: asfood-tomato # 指定config server在服务发现中的serviceId,默认为:configserver
#由于服务端配置了访问需要用户名和密码,所以此处也需要配置
username: tomato
password: tomato
application.yml
server:
port: 55591 spring:
application:
name: asfood-ketchup
profiles:
active: dev #日志
logging:
file: ./logs/ketchup.log management:
security:
enabled: false #actuator是否需要安全保证 默认为true 不加会报错
现在启动服务端,后启动客户端,可以访问就正常了,
如果客户端启动报错:找不到所配置的读取的文件中的key, xxx placeholder ${xxx} 这个错误就是没有找到配置文件(保证不会手误,key写的不一样),如果此时你的服务端的页面访问配置文件,不能访问到配置文件中的内容,这个需要再次百度,如果是服务端可以访问到配置文件中的内容,这个时候需要检查客户端的服务端地址等的配置,检查服务端和客户端启动类的注释,一个是server一个是client还有问题百度吧,我也初学。。。还有个好网站,stackoverflow。
自动刷新配置文件访问: 客户端ip:port/refresh
有需要可以参考这里(在asfood-ketchup-config-client和asfood-tomato-config-server中): https://github.com/molyjao/mlims.git
springboot+springcloud config的更多相关文章
- Springboot属性加载与覆盖优先级与SpringCloud Config Service配置
参考官方文档:https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config. ...
- springcloud情操陶冶-springcloud config server(一)
承接前文springcloud情操陶冶-springcloud context(二),本文将在前文基础上浅析下ConfigServer的工作原理 前话 根据前文得知,bootstrapContext引 ...
- SpringCloud-微服务配置统一管理SpringCloud Config(七)
前言:对于应用,配制文件通常是放在项目中管理的,它可能有spring.mybatis.log等等各种各样的配置文件和属性文件,另外你还可能有开发环境.测试环境.生产环境等,这样的话就得一式三份,若是传 ...
- 【原创】SpringBoot & SpringCloud 快速入门学习笔记(完整示例)
[原创]SpringBoot & SpringCloud 快速入门学习笔记(完整示例) 1月前在系统的学习SpringBoot和SpringCloud,同时整理了快速入门示例,方便能针对每个知 ...
- 带你入门SpringCloud统一配置 | SpringCloud Config
前言 在微服务中众多服务的配置必然会出现相同的配置,如果配置发生变化需要修改,一个个去修改然后重启项目的方案是绝对不可取的.而 SpringCloud Config 就是一个可以帮助你实现统一配置选择 ...
- SpringBoot SpringCloud 热部署 热加载 热调试
疯狂创客圈 Java 高并发[ 亿级流量聊天室实战]实战系列 [博客园总入口 ] 架构师成长+面试必备之 高并发基础书籍 [Netty Zookeeper Redis 高并发实战 ] Crazy-Sp ...
- springcloud Config 入门,带视频
疯狂创客圈 Java 高并发[ 亿级流量聊天室实战]实战系列 [博客园总入口 ] 架构师成长+面试必备之 高并发基础书籍 [Netty Zookeeper Redis 高并发实战 ] 前言 Crazy ...
- springboot + springcloud +nacos实战
首先从整个软件的功能和应用场景来说,nacos更像consul,而非eureka,nacos设计的时候自带的配置中心功能,让我们省下了去搞springcloud config的时间,但这里并不是说na ...
- SpringCloud学习笔记(二、SpringCloud Config)
目录: 配置中心简介 SpringCloud Config服务端 SpringCloud Config客户端 动态配置属性bean 一些补充(源码分析):Spring事件监听.健康检查health() ...
随机推荐
- cocos2dx打飞机项目笔记四:Enemy类和EnemyLayer类
Enemy类没什么内容,就create和init方法,根据参数来创建不同的敌机,头文件代码如下: //飞机的类型 enum planeType {smallPlane, midPlane, bigPl ...
- FIND_IN_SET的简单使用
FIND_IN_SET(str,strlist)函数 str 要查询的字符串 strlist 字段名 参数以”,”分隔 如 (1,2,6,8) 查询字段(strlist)中包含(str)的结果,返回结 ...
- HDU 5877 Weak Pair (2016年大连网络赛 J dfs+反向思维)
正难则反的思想还是不能灵活应用啊 题意:给你n个点,每个点有一个权值,接着是n-1有向条边形成一颗有根树,问你有多少对点的权值乘积小于等于给定的值k,其中这对点必须是孩子节点与祖先的关系 我们反向思考 ...
- 中文乱码之myEclipse项目导入时中文乱码(待)
方法1:检查默认的编码是否设置成utf-8. 步骤如图: window——>preferences... 若Text file encoding 中的编码为 Other == UTF-8 ,则已 ...
- eclipse安装hibernate插件(在线Marketplace中安装)
网上很多都是给个网址,然后在eclipse的help中new install soft中安装.每次安装还要去查找最新的地址去安装.为什么不用eclipse的marketplace直接搜索安装呢? 打开 ...
- 医院Android项目总结
Eclipse ADT 配置AVD 1.layout布局:xml 如ck_report.xml <Text view ...android:id="ck"> & ...
- 子矩阵(暴搜(全排列)+DP)
子矩阵(暴搜(全排列)+DP) 一.题目 子矩阵 时间限制: 1 Sec 内存限制: 128 MB 提交: 1 解决: 1 [提交][状态][讨论版] 题目描述 给出如下定义: 1. 子矩阵:从一 ...
- dp4--codeVs1043 方格取数
dp4--codeVs1043 方格取数 一.心得 二.题目 1043 方格取数 2000年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Dia ...
- @angular/cli项目构建--路由2
app.module.ts update const routes: Routes = [ {path: '', redirectTo: '/home', pathMatch: 'full'}, {p ...
- datatable绑定comboBox,在下拉菜单中显示对应数据
实现功能: datatable绑定comboBox,在下拉菜单中显示对应数据 实现方法: .生成datatable,并为combox绑定数据源: comboBox1.DataSource = dt1; ...