You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.7KB

  1. package vn.azteam.tpf.config;
  2. import io.github.jhipster.config.JHipsterConstants;
  3. import org.springframework.boot.SpringApplication;
  4. import org.springframework.core.env.Environment;
  5. import java.util.*;
  6. /**
  7. * Utility class to load a Spring profile to be used as default
  8. * when there is no <code>spring.profiles.active</code> set in the environment or as command line argument.
  9. * If the value is not available in <code>application.yml</code> then <code>dev</code> profile will be used as default.
  10. */
  11. public final class DefaultProfileUtil {
  12. private static final String SPRING_PROFILE_DEFAULT = "spring.profiles.default";
  13. private DefaultProfileUtil() {
  14. }
  15. /**
  16. * Set a default to use when no profile is configured.
  17. *
  18. * @param app the Spring application
  19. */
  20. public static void addDefaultProfile(SpringApplication app) {
  21. Map<String, Object> defProperties = new HashMap<>();
  22. /*
  23. * The default profile to use when no other profiles are defined
  24. * This cannot be set in the <code>application.yml</code> file.
  25. * See https://github.com/spring-projects/spring-boot/issues/1219
  26. */
  27. defProperties.put(SPRING_PROFILE_DEFAULT, JHipsterConstants.SPRING_PROFILE_DEVELOPMENT);
  28. app.setDefaultProperties(defProperties);
  29. }
  30. /**
  31. * Get the profiles that are applied else get default profiles.
  32. *
  33. * @param env spring environment
  34. * @return profiles
  35. */
  36. public static String[] getActiveProfiles(Environment env) {
  37. String[] profiles = env.getActiveProfiles();
  38. if (profiles.length == 0) {
  39. return env.getDefaultProfiles();
  40. }
  41. return profiles;
  42. }
  43. }