Comments (10)
是否是所有的配置项都可以从config server来获取
可以的。
是否需要自己获取这些配置内容再来手动创建相应的数据库连接,还是有什么方法可以自动实现,谢谢
自动与否得看情况。引入spring-cloud-config-client后,就会有两个上下文,引导上下文bootstrap context以及applicationcontext。启动时,bootstrap context负责获取远程的配置文件属性。
对于数据源,spring boot会自动创建,只要你有相关的starter;而如果你没有相关的starter,那就得自己new了。
说白了,引入config的作用其实就是将嵌入在jar包中的配置实现集中化的远程管理。其他的原先怎么样现在还是怎么样。
from spring-cloud-docker-microservice-book-code.
不好意思,又来打扰了,可能是我有些地方理解得还不是很透彻,不知道是否可以写一篇关于从config-server获取数据库配置信息并依据该配置信息实现hibernate对数据库操作,或者把关键的配置信息贴出来,谢谢
from spring-cloud-docker-microservice-book-code.
- 微服务集成config-client
- git仓库里存数据库url、账号、密码等信息;
- 自动拿。
- 如果你愿意,可以加密。
跟我开源书里用法一样。
from spring-cloud-docker-microservice-book-code.
貌似Config client 在启动的时候报错,
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'miss-lili' in string value "${miss-lili}"
网上查了不少资料,好像是bootstrap的启动顺序不太对
from spring-cloud-docker-microservice-book-code.
从报错来看,是应用没有能够正常从git仓库拿到配置文件。
可能的原因有很多:
- 应用的spring.application.name 和git仓库里包含
miss-lili
属性的的配置文件名称不匹配; - config server无法正常连接上git仓库。建议在启动config client微服务之前用config server的REST端点测试并确认。
- config client连接的config server地址不对。例如:将应用名称、config server地址等等配置在了
application.*
中,而非bootstrap.*
等。
from spring-cloud-docker-microservice-book-code.
对于config这块一直也有一个小疑问,这个模块有个/refresh 手动刷新的功能,它的可以动态刷新配置,但是类似线程池的配置 项目启动时候就初始化了 后期如果想修改线程池大小,这个手动刷新是不是也不能直接完成修改线程池大小 还得重启程序。
PS:网上有些博客写的给我的感觉 只要refresh了 什么配置都能修改 不用重启项目,如果不用重启项目,那config这个组件是如何实现动态修改线程池类似的配置呢?
from spring-cloud-docker-microservice-book-code.
@mrsWangxing 刷新是有前置要求的
- 要刷新的属性所在的类上得有@RefreshScope,否则无法刷新
- 应用得继承config-cilent以及spring-boot-starter-actuator,否则没有refresh端点
刷新的本质,其实就是调用了这行代码,有兴趣看看:org.springframework.cloud.context.refresh.ContextRefresher#refresh
,网上的文章可以看,不过看完文章,然后就靠感觉判断xxx,我觉得不靠谱。还是做实验去验证自己的感觉比较OK。
from spring-cloud-docker-microservice-book-code.
比如线程池那样的 服务器启动 直接加载初始化的 对象 加上 @RefreshScope等前置要求 不启动服务器也可以实现 刷新吗 ?之前还真没试过。
from spring-cloud-docker-microservice-book-code.
@mrsWangxing 这是spring cloud提供的注解。不一定要有web容器(Tomcat),只要你的bean是个spring管理的对象。
from spring-cloud-docker-microservice-book-code.
OK 懂了 谢谢
from spring-cloud-docker-microservice-book-code.
Related Issues (11)
- No qualifying bean of type 'javax.sql.DataSource' available: HOT 1
- 原书第二版67页的DefaultRibbonConfig的IClientConfig启动时报bean不存在,源码中也搜索不到,请问这个类的Bean需要自己实现吗?
- Actuator info not Hystrix info HOT 1
- 原书第二版174页Config Server模式匹配simple报错nested exception is java.lang.IllegalStateException HOT 3
- Spring Cloud Eureka高可用 HOT 2
- microservice-config-client-refresh-cloud-bus tracebck HOT 3
- microservice-consumer-movie-feign-manual HOT 3
- microservice-simple-provider-user 编译报错饱思不得其解 HOT 2
- microservice-simple-provider-user 启动报错 HOT 3
- feign 怎么配置像ribbon一样可以选择调度策略呢 HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-cloud-docker-microservice-book-code.