SpringBoot中用于环境判断的配置类ProfileConfig

作用:读取SpringBoot中用于多环境切换的配置spring.profiles.active,利用其进行环境的判断(开发环境、测试环境、生产环境等)

折叠复制代码
  1. /**
  2. * Profile环境配置
  3. */
  4. @Configuration
  5. public class ProfileConfig {
  6. @Value("${spring.profiles.active:dev}")
  7. private String profile;
  8. /**
  9. * 当前是否是开发环境
  10. *
  11. * @return
  12. */
  13. public boolean isDev() {
  14. return "dev".equalsIgnoreCase(profile);
  15. }
  16. /**
  17. * 当前是否是测试环境
  18. *
  19. * @return
  20. */
  21. public boolean isTest() {
  22. return "test".equalsIgnoreCase(profile);
  23. }
  24. /**
  25. * 当前是否是生产环境
  26. *
  27. * @return
  28. */
  29. public boolean isPrd() {
  30. return "dev".equalsIgnoreCase(profile);
  31. }
  32. }

觉得内容还不错?打赏个钢镚鼓励鼓励!!👍