In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what is the use of native mode in Spring Cloud Config configuration center". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Background description
Because most of the time, the production environment does not have git, svn, etc., so we need to use native mode. In view of the lack of relevant information on the Internet, we take this as a starting point to record some common functions of Spring Cloud Config in native mode.
Config-server configuration
First of all, the old routine introduces pom.
Org.springframework.cloud spring-cloud-config-server
Bootstrap.yml configuration local storage official documentation here
Spring.profiles.active=composite, he is a list, because we are local, add a type=native, and match it with search-locations. This attribute can be class-path or absolute path, but under normal circumstances, it is recommended to use absolute path, because the configuration file will be changed. If you put it in the project, it will be troublesome to change.
Also set up pring.cloud.config.server.bootstrap=true
Under the config folder, I put three files, config-info-dev.yml,config-info-test.yml,config-info-prod.yml, which contain impassable content, mainly for testing
Server: port: 8001spring: application: name: config-server-1 profiles: active: composite cloud: config: server: composite:-type: native # the absolute path to the file. I put it in resources as an absolute path in the source code. Here, you need to change your own path search-locations: file:///Users/sunhan/Downloads/config bootstrap: true
Startup class
@ SpringBootApplication@EnableConfigServerpublic class EurekaConfigApp {public static void main (String [] args) {SpringApplication.run (EurekaConfigApp.class, args);}}
At this point, config-server temporarily announced a section of the way.
Config-client configuration
Go ahead, introduce pom
Org.springframework.cloud spring-cloud-config-client org.springframework.boot spring-boot-starter-web
Client adds two configuration files, one bootstrap.yml, and the official document also says If you use the bootstrap flag, the config server needs to have its name and repository URI configured in bootstrap.yml. The main explanation of config is as follows
Uri: the request path of config-server
Profile, name: there is no relationship between profile and spring.profiles.active. He only distinguishes and references that file. For example, the configuration file config-info-dev.yml,name is config-info,profile is dev, and there is also a label attribute. The official interpretation is The label name to use to pull remote configuration properties. My understanding is that it should be used in remote repositories such as git, at least in terms of file matching, profile and name are sufficient.
Spring: cloud: config: uri: http://localhost:8001 profile: prod name: config-info
Another is the application.yml file of spring-boot, where the default value of spring.cloud.config.name is spring.application.name
Server: port: 8002spring: application: name: config-info profiles: # this is mainly to disguise the distinction from config.profile active: dev
Finally, post the startup class
@ SpringBootApplicationpublic class ConfigClientApp1 implements CommandLineRunner {public static void main (String [] args) {SpringApplication.run (ConfigClientApp1.class, args);} @ Value ("${env}") private String env; @ Value ("${hello}") private String hello; public void run (String... Args) {System.out.println ("="); System.out.println (env); System.out.println (hello); System.out.println ("=");}}
Enter the result
= prod1dev=
Next, it's time to think about refreshing. Manual refresh, or integration of Spring Cloud Bus hot refresh, next time talk
This is the end of the content of "what is the use of native mode in Spring Cloud Config configuration center". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.