配置文件中的配置,在程序中关联起来,就是上面的几个配置。
其中在配置文件当中,还能够通过占位符,做一点小技巧。
配置文件占位符
@ConfigurationProperties - application.properties
@Value - 单值
@PropertySource - person.properties
@ImportResource - spring配置的bean.xml
随机数占位符
RandomValuePropertySource:配置文件中可以使用随机数
${random.value}
${random.int}
${random.long}
${random.int(10)}
${random.int[1024,65536]}
属性配置占位符
- 可以在配置文件当中引用前面配置过的属性,优先级前面配置过的这里都能用。
- ${app.name:默认值}来制定找不到属性时的默认值
app.name=MyApp
app.description=${app.name:hello} is a Spring Boot application