public ConfigClientProperties(Environment environment) { String[] profiles = environment.getActiveProfiles(); if (profiles.length == 0) { profiles = environment.getDefaultProfiles(); } this.setProfile(StringUtils.arrayToCommaDelimitedString(profiles)); }
/** * Get the profiles that are applied else get default profiles. */ public static String[] getActiveProfiles(Environment env) { String[] profiles = env.getActiveProfiles(); if (profiles.length == 0) { return env.getDefaultProfiles(); } return profiles; } }
@PostConstruct public void postConstruct() { System.out.println("================== " + DebugBean.class.getName() + "================================="); System.out.println("active profiles: " + on(",").join(env.getActiveProfiles())); System.out.println("default profiles: " + on(",").join(env.getDefaultProfiles())); System.out .println("spring.database.driverClassName: " + env.getProperty("spring.database.driverClassName")); System.out.println("spring.jpa.hibernate.ddl-auto: " + env.getProperty("spring.jpa.hibernate.ddl-auto")); System.out.println("all beans:"); stream(context.getBeanDefinitionNames()).forEach(System.out::println); System.out.println("================== " + DebugBean.class.getName() + "================================="); }
public GcpConfigProperties(Environment environment) { if (this.profile == null) { String[] profiles = environment.getActiveProfiles(); if (profiles.length == 0) { profiles = environment.getDefaultProfiles(); } if (profiles.length > 0) { this.profile = profiles[profiles.length - 1]; } else { this.profile = "default"; } } }
@Autowired public EnvServiceImpl(VersionInfoConfig version, OntrackConfigProperties configProperties, ApplicationContext ctx) { this.defaultProfiles = StringUtils.join(ctx.getEnvironment().getDefaultProfiles(), ","); this.profiles = StringUtils.join(ctx.getEnvironment().getActiveProfiles(), ","); // Version information from the configuration this.version = version.toInfo(); // JDBC URL this.jdbcUrl = ctx.getEnvironment().getProperty("spring.datasource.url"); // Home directory this.home = new File(configProperties.getApplicationWorkingDir()); }
public ConfigClientProperties(Environment environment) { String[] profiles = environment.getActiveProfiles(); if (profiles.length == 0) { profiles = environment.getDefaultProfiles(); } this.setProfile(StringUtils.arrayToCommaDelimitedString(profiles)); }
/** * 能够获取原来配置,可以用的初始化方式 */ public static void init(@NonNull Environment environment) { //取Spring的profile作为环境区分的标识 List<String> activeProfileList = Arrays.stream(environment.getActiveProfiles()) .collect(Collectors.toList()); String mainProfile = activeProfileList.stream() .findFirst() .orElse(environment.getDefaultProfiles()[0]); DictatorClientProperties dictatorClientProperties = DictatorClientProperties.of(); dictatorClientProperties.setProfile(mainProfile); dictatorClientProperties.setServerUrl(environment.getProperty("dictator.serverUrl")); dictatorClientProperties.setAppCode(environment.getProperty("dictator.appCode")); dictatorClientProperties.setProfile(mainProfile); // 打印参数 dictatorClientProperties.printCurrent(); //验证参数 dictatorClientProperties.verify(); DICTATOR_CLIENT = DictatorClient.of(dictatorClientProperties); DictatorPropertyManager.refreshCache(); }