Reasonable configuration centers have the following functions:
提供服务端和客户端支持
集中管理各环境的配置文件
配置文件修改之后,可以快速的生效
可以进行版本管理
支持大的并发查询
支持各种语言
Spring Cloud Config can support all of the above requirements perfectly.
Spring cloud using git or svn to store configuration files, use the default git, git, for example to make a set of examples.
end server
Start classes are added @EnableConfigServer
, activate support for configuration center
Request Address: HTTP: // localhost: 8001 / Neo-config / the Test
git Address: https://github.com/shihongwei/springcloud-config-server
client end
We need to configure two configuration files, application.properties and bootstrap.properties
application.properties as follows:
spring.application.name=spring-cloud-config-client
server.port=8002
bootstrap.properties as follows:
spring.cloud.config.name=neo-config
spring.cloud.config.profile=dev
spring.cloud.config.uri=http://localhost:8001/
spring.cloud.config.label=master
Special Note: The above associated with spring-cloud properties must be configured in bootstrap.properties, the inner part of config> content can be loaded correctly?. Because of config configuration will precede application.properties, and bootstrap.properties> is loaded prior to application.properties.
Start class need only @SpringBootApplication
comment on it
Use @Value
annotation server to obtain an end value of the parameter
@RestController
class HelloController {
@Value("${config.hello}")
private String hello;
@RequestMapping("/hello")
public String getHello() {
return hello;
}
}
After starting the project visit:http://localhost:8002/hello
git Address: https://github.com/shihongwei/springcloud-config-client
Let us make some small experiments, manually modify neo-config-test.properties
the configuration information: config.hello=hello in test update
submission to github, again in the browser to access the http://localhost:8002/hello
returns: hello in test
, descriptive information or old parameter acquisition, which is why? Because springboot project will start only when the acquisition value of the configuration file, modify github information, client-side and did not get to go in the second, resulting in the problem. How to solve this problem? We leave to the next chapter in the introduction.
Reference: pure smile
http://www.ityouknow.com/springcloud/2017/05/22/springcloud-config-git.html
Reproduced in: https: //www.jianshu.com/p/6d8a54f52d6c