In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "Spring Cloud Alibaba Nacos Config Instance Analysis". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian slowly and deeply to study and learn "Spring Cloud Alibaba Nacos Config Instance Analysis" together!
1, Install Nacos1, Download Nacos
Download the latest stable version: github.com/alibaba/nacos/releases
2. Start Nacos
Start Nacos (standalone mode)
sh startup.sh -m standalone
Close Nacos
sh shutdown.sh II. Configure Nacos1. Open Nacos
Default address: 127.0.0.1:8848/nacos/#/login
Default account: Same account password, both nacos
2. Add configuration
Configuration data:
Data ID: nacos-dev.propertiesGroup : DEFAULT_GROUP Configuration format: Properties Configuration Content: useLocalCache=true
Data ID format description:
${prefix}-${spring.profile.active}.$ {file-extension}
prefix:
Default is spring.application.name value, can also be configured through the configuration item spring.cloud.nacos.config.prefix
spring.profile.active:
That is, the profile corresponding to the current environment. Note: When spring.profile.active is empty, the corresponding connector-will not exist, and the concatenation format of dataId will be changed to ${prefix}.$ {file-extension}
file-exetension:
To configure the data format of the content, you can configure it through the configuration item spring.cloud.nacos.config.file-extension. Currently only properties and yaml types are supported
Examples:
spring.application.name=nacosspring.profiles.active=devspring.cloud.nacos.config.file-extension=properties
Data ID is: nacos-dev.properties
III. Use of Nacos
Add nacos support to pom.xml
org.springframework.cloud spring-cloud-starter-alibaba-nacos-config 0.9.0.RELEASE
bootstrap.properties Add nacos parameter
server.port=8080spring.profiles.active=devspring.application.name=nacosspring.cloud.nacos.config.server-addr=127.0.0.1:8848spring.cloud.nacos.config.file-extension=properties
spring.cloud.nacos.config.server-addr: Server address for nacos: port, port 80 cannot be omitted
spring.cloud.nacos.config.file-extension: supported file types for nacos, e.g. yaml and properties
IV. Call Nacos
@Value SpEL call
@RefreshScope Turn on auto-refresh
package com.ichochy.nacos.controller;import org.springframework.beans.factory.annotation.Value;import org.springframework.cloud.context.config.annotation.RefreshScope;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestController@RequestMapping("/config")@RefreshScopepublic class ConfigController { @Value("${useLocalCache:false}") private boolean useLocalCache; @RequestMapping("get") public boolean getConfig(){ System.out.println(useLocalCache); return useLocalCache; }} Thank you for reading, the above is the content of "Spring Cloud Alibaba Nacos Config instance analysis", after learning this article, I believe that everyone has a deeper understanding of Spring Cloud Alibaba Nacos Config instance analysis, and the specific use needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
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.