The server provides resource-based HTTP for external configuration (name-value pairs or equivalent yaml content). The server can be @EnableConfigServer
easily embedded in the spring boot application using annotations. So this application is a configuration server:
Configserver.java
@SpringBootApplication @EnableConfigServer publicclass configserver { Public Static void Main (string[] args) { springapplication.run (configserver. class , args); } }
Like all spring boot applications running on the default port 8080, you can switch them to regular port 8888 in a variety of ways. The simplest is also to set a default configuration library, which is done by starting it spring.config.name=configserver
(there is one in the Config Server jar configserver.yml
). The other is to use your own application.properties
, for example
Application.properties
server.port:8888 spring.cloud.config.server.git.uri:file://${user.home}/config-repo
${user.home}/config-repo
This is the Git repository that contains Yaml and properties files.
Here's how to create a git repository in the example above:
Tip |
Here's how to create a git repository in the example above: $ cd $HOME$ mkdir config-repo$ cd config-repo$ git init .$ echo info.foo: bar > application.properties$ git add -A .$ git commit -m "Add application.properties" |
Warning using a local file system for a git repository is for testing only. Use the server to host the configuration library in a production environment. If you keep only text files, the initial cloning of the configuration library will be quick and efficient. If you start to store binaries, especially large files, you may experience delays in the first configuration request and/or out-of-memory errors in the server
完整项目的源码来源 技术支持求求1791743380
Spring Cloud config server