yml文件
可能需要这个:
<!-- 自定义的元数据依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId><optional>true</optional></dependency>
读取
// 方法一(直接读取):@Value("${neo.title}")private String title;// 方法二(快速封装多个值)@Component@ConfigurationProperties(prefix="neo")public class NeoProperties {private String title;private String description;//省略getter settet方法}// 方法三(读取自定义配置文件里面的值,例如:other.properties )@Component@ConfigurationProperties(prefix="other")@PropertySource("classpath:other.properties")public class OtherProperties {private String title;private String blog;//省略getter settet方法}
更新
# 1、添加引用<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-context</artifactId></dependency># 2、调用刷新函数@Autowiredprivate ContextRefresher contextRefresher;/*** 刷新并返回日志缓存时间* @return*/@GetMapping("/getExist")public Integer getExistTime() {contextRefresher.refresh();return logScheduling.getLogExistDays();}
随机数
secret=${random.value}number=${random.int}bignumber=${random.long}uuid=${random.uuid}number.less.than.ten=${random.int(10)}number.in.range=${random.int[1024,65536]}
