标签:static 代码 示例 请求 nas 认证 star ram 刷新
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId></dependency>
aoolication.properties
spring.application.name=config-server server.port=8001 #读取本地文件 spring.profiles.active=native
在src/main/resources下添加config-dev.properties,config-test.properties,config-pro.properties
每个配置文件中都写一个属性env,属性值分别是 dev/test/pro
@EnableConfigServer //激活对配置中心的支持 @SpringBootApplication public class ConfigServerApplication { public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); } }
http://localhost:8001/config-dev.properties
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency>
bootstrap.properties
spring.cloud.config.name=config spring.cloud.config.profile=dev spring.cloud.config.uri=http://localhost:8001/
@SpringBootApplication @EnableDiscoveryClient //使项目有服务注册功能 public class ProviderApplication { public static void main(String[] args) { SpringApplication.run(ProviderApplication.class, args); } }
@RestController //@RefreshScope @RequestMapping("/dynasty") public class DynastyController { @Value("${env}") private String env; @RequestMapping("/hello") public String hello(@RequestParam String name) { return "hello, " + name + ":" + env; } }
@RestController @RefreshScope // 使用该注解的类,会在接到SpringCloud配置中心配置刷新的时候,自动将新的配置更新到该类对应的字段中 @RequestMapping("/dynasty") public class DynastyController { @Value("${env}") private String env; @RequestMapping("/hello") public String hello(@RequestParam String name) { return "hello, " + name + ":" + env; } }
application.properties
添加以下配置
management.security.enabled=false
十九、springcloud(五)配置中心本地示例和refresh
标签:static 代码 示例 请求 nas 认证 star ram 刷新
原文地址:https://www.cnblogs.com/monkeybrother/p/9792655.html