package com.java1234.controller;import org.springframework.beans.factory.annotation.Value;import org.springframework.cloud.context.config.annotation.RefreshScope;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/nacos")
@RefreshScope
public class NacosConfigController {
@Value("${java1234.name}")
private String name;
@Value("${java1234.age}")
private String age;
@GetMapping("/getConfigInfo")
public String getConfigInfo(){
return name+":"+age;}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.java1234;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class NacosConfigApplication {
public static void main(String[] args){
SpringApplication.run(NacosConfigApplication.class,args);}}