注解小知识
从配置文件中获取数据信息
@Component
@ConfigurationProperties(prefix = "dog")
配置文件
server:
port: 8080
dog:
name: 张三
age: 18
你可以使用此类注解从配置文件中中获取配置,配置文件最好位yml,可以减少很多冗余代码
JSR303数据校检
@Validated
使用此注解可以在属性上机型数据校检
生产环境测试环境切换
application.properties
application-test.properties
application-dev.properties
spring.profiles.active=test
yml配置文件可以使用—进行分割
application.yml
# 选择激活那个版本
server:
port: 8080
spring:
profiles:
active: dev
---
#版本
server:
port: 8081
spring:
profiles: dev
---
server:
port: 8082
spring:
profiles: test