Before springboot project constants like the following form:
@Component added when the central configuration // nacos RefreshScope @ public class the Constants { @Value ( "test1 $ {}" ) public String test1; }
Then write test1 = 123 in the configuration file properties in
controller application
@Autowired private Constants constants;
@GetMapping("/test")
public String test(){
logger.info("constants :{}",constants);------------------------------------------ 1
logger.info ( "Test Center nacos configuration updates in real time: {}" ., Constants test1 ); --------------- 2
return constants.test1;------------------------------------------------- 3
}
Before configuring nacos not used as a center are ok, but after using nacos distribution center, after configured in accordance with springcloud way to start on the problem arises
The problem is at 1 constants is not empty, but the values are null 2,3
Solution:
The upper getter / setter Constants added, and then use the value constants.getTest1 () to get the value