文章字数:324,阅读全文大约需要1分钟
application.properties是保存spring配置的地方。springBoot提供了很多模块,只需要在pom中引入模块化的
starter POMs
(spring-boot-starter-*,ru dara-jpa这些spring整合的模块)。除了这些模块的应用外,还能有其他特殊的使用场景。
自定义属性及加载
1 | //key=value 类型 |
在变量上加上注解,自动加载值
1 | //属性名 |
参数间引用
1 | xxx.demo.test=test |
随机数
1 | # 随机字符串 |
屏蔽命令行修改属性值
java -jar xxx.jar --server.port=888
等价于在配置文件中设置xxx.jar,--
是对于配置属性赋值的标识。
- 屏蔽修改属性
1
SpringApplication.setAddCommandLineProperties(false)
多环境配置
就是生产、测试、开发环境都用各自的配置文件
- application-dev.properties:开发环境
- application-test.properties:测试环境
- application-prod.properties:生产环境
在主配置文件application.properties
中spring.profiles.active
配置机体需要那一份配置。(rest,dev,prod)
也可以命令行选则1
java -jar xxx.jar --spring.profiles.active=test