ConfigurationProperties 注解
①新增类
@Data
@ConfigurationProperties(prefix = "xx.aaxx")
public class ContentProperties {/*** 内容*/private String content;}
②配置文件application.properties
xx.aaxx.content=热更内容
③使用
@Autowiredprivate ContentProperties contentProperties;// 使用String content = contentProperties.getContent();
Value 注解
①配置文件application.properties
xx.aaxx.content=热更内容
②使用
@Value("${xx.aaxx.content:默认内容}")private String content;// 使用System.out.println(content)
结
就算配置文件application.properties 没有配置,也可以使用默认内容,这样启动就不会报错,如果没有默认值就必需写配置项
以上两种方式都可以实现:
无需更改代码去发布,只需要热更配置即可 像Nacos等就更加方便了,服务都不用重启