List of usage examples for org.springframework.context ConfigurableApplicationContext getEnvironment
@Override ConfigurableEnvironment getEnvironment();
From source file:alfio.config.SpringBootLauncher.java
/** * Entry point for spring boot/* w w w. ja va 2s .co m*/ * @param args original arguments */ public static void main(String[] args) { Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler()); String profiles = System.getProperty("spring.profiles.active", ""); SpringApplication application = new SpringApplication(SpringBootInitializer.class, RepositoryConfiguration.class, DataSourceConfiguration.class, WebSecurityConfig.class, MvcConfiguration.class); List<String> additionalProfiles = new ArrayList<>(); additionalProfiles.add(Initializer.PROFILE_SPRING_BOOT); if ("true".equals(System.getenv("ALFIO_LOG_STDOUT_ONLY"))) { // -> will load application-stdout.properties on top to override the logger configuration additionalProfiles.add("stdout"); } if ("true".equals(System.getenv("ALFIO_DEMO_ENABLED"))) { additionalProfiles.add(Initializer.PROFILE_DEMO); } if ("true".equals(System.getenv("ALFIO_JDBC_SESSION_ENABLED"))) { additionalProfiles.add(Initializer.PROFILE_JDBC_SESSION); } application.setAdditionalProfiles(additionalProfiles.toArray(new String[additionalProfiles.size()])); ConfigurableApplicationContext applicationContext = application.run(args); ConfigurableEnvironment environment = applicationContext.getEnvironment(); log.info("profiles: requested {}, active {}", profiles, String.join(", ", (CharSequence[]) environment.getActiveProfiles())); if ("true".equals(System.getProperty("startDBManager"))) { launchHsqlGUI(); } }
From source file:com.hillert.botanic.MainApp.java
/** * Main class initializes the Spring Application Context and populates seed * data using {@link SeedDataService}.//from w ww .jav a2 s .com * * @param args Not used. */ public static void main(String[] args) { Map<String, Object> props = new HashMap<String, Object>(); props.put("redisPort", SocketUtils.findAvailableTcpPort()); SpringApplication app = new SpringApplication(MainApp.class); app.setDefaultProperties(props); ConfigurableApplicationContext context = app.run(args); MapPropertySource propertySource = new MapPropertySource("ports", props); context.getEnvironment().getPropertySources().addFirst(propertySource); SeedDataService seedDataService = context.getBean(SeedDataService.class); seedDataService.populateSeedData(); }
From source file:org.greencheek.utils.environment.propertyplaceholder.examples.spring.profile.AppBootstrap.java
public static void initialise(ConfigurableApplicationContext applicationContext) { applicationContext.getEnvironment().getPropertySources() .addFirst(new PropertiesPropertySource("p", environmentalProperties)); }
From source file:com.example.config.ApplicationBuilder.java
public static void start(ConfigurableApplicationContext context) { if (!hasListeners(context)) { ((DefaultListableBeanFactory) context.getBeanFactory()).registerDisposableBean(SHUTDOWN_LISTENER, new ShutdownApplicationListener()); new BeanCountingApplicationListener().log(context); logger.info(STARTUP);//from w w w. j a v a 2 s . co m } HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build(); ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler); HttpServer httpServer = HttpServer.create().host("localhost") .port(context.getEnvironment().getProperty("server.port", Integer.class, 8080)).handle(adapter); httpServer.bindUntilJavaShutdown(Duration.ofSeconds(60), disposable -> disposable.dispose()); }
From source file:spr8991.Spr8991ACI.java
@Override public void initialize(ConfigurableApplicationContext applicationContext) { String answer = applicationContext.getEnvironment().getRequiredProperty("answer"); assertThat(answer, is("42")); }
From source file:org.cloudfoundry.test.TestApplicationContextInitializer.java
@Override public void initialize(ConfigurableApplicationContext applicationContext) { String profile = applicationContext.getEnvironment().getProperty("TEST_PROFILE"); log.info("Using profile " + profile); if (profile == null || profile.isEmpty()) { applicationContext.getEnvironment().setActiveProfiles("cloud-services"); } else {//w w w .j a va2 s . co m applicationContext.getEnvironment().setActiveProfiles(profile); } }
From source file:org.cloudfoundry.reconfiguration.spring.CloudProfileApplicationContextInitializer.java
@Override public void initialize(ConfigurableApplicationContext applicationContext) { listener.addCloudProfile(applicationContext.getEnvironment()); }
From source file:io.fabric8.spring.cloud.kubernetes.profile.KubernetesApplicationContextInitializer.java
@Override public void initialize(ConfigurableApplicationContext applicationContext) { listener.addKubernetesProfile(applicationContext.getEnvironment()); }
From source file:com.pavikumbhar.javaheart.springconfiguration.ContextInitializer.java
@Override public void initialize(ConfigurableApplicationContext applicationContext) { ConfigurableEnvironment environment = applicationContext.getEnvironment(); System.out.println("com.pavikumbhar.javaheart.ContextInitializer.initialize()"); try {/*from w ww . ja v a 2 s. c o m*/ environment.getPropertySources().addFirst(new ResourcePropertySource("classpath:env.properties")); String profile = environment.getProperty("spring.profiles.active"); environment.setActiveProfiles(profile); System.err.println(" spring.profiles.active profile :" + profile); System.err.println("env.properties loaded :" + ContextInitializer.class.getName()); } catch (IOException e) { // it's ok if the file is not there. we will just log that info. System.out.println( "didn't find env.properties in classpath so not loading it in the AppContextInitialized"); } }
From source file:com.iflytek.edu.cloud.frame.spring.ProfileApplicationContextInitializer.java
@Override public void initialize(ConfigurableApplicationContext applicationContext) { String[] profiles = EnvUtil.getSpringProfiles(); applicationContext.getEnvironment().setActiveProfiles(profiles); _logger.info("Active spring profile: {}", StringUtils.join(profiles, ",")); }