选择配置环境profiles(正式、测试之间调换)
作者:互联网
配置类中手动修改
简单配置
1.配置类
application.properties -- 主配置类
spring.profiles.active=test
application-prod.yaml -- 正式环境配置类
user: name: 正式环境 age: 20 server: port: 5050
application-test.yaml -- 测试环境配置类
user: name: 测试环境 age: 21 server: port: 6060
2.Controller
@Controller public class MyController { @Autowired private User user; @ResponseBody @GetMapping("/getUser") public User getUser(){ return user; } }
3.实体类
@Data @ToString @ConfigurationProperties("user") @Component public class User { private String name; private int age; }
4.请求
复杂配置
1.配置类
application-prod.yaml -- 主配置类
spring.profiles.active=myprod spring.profiles.group.myprod[0]=prod spring.profiles.group.myprod[1]=prod-age
spring.profiles.group.mytest[0]=test
application-prod1.yaml -- 生产环境配置类
user: userName: 正式环境 server: port: 5050
application-prod-age.yaml -- 生产环境配置类2
user: age: 20
application-test.yaml -- 测试环境配置类
user: userName: 测试环境 age: 21 server: port: 6060
2.Controller
@Controller public class MyController { @Autowired private User user; @ResponseBody @GetMapping("/getUser") public User getUser(){ return user; } }
3.实体类
@Data @ToString @ConfigurationProperties("user") @Component public class User { private String name; private int age; }
4.请求
标签:--,调换,age,配置,profiles,application,private,user,测试 来源: https://www.cnblogs.com/dabo-tian/p/16586999.html