Java Code Examples for org.springframework.boot.SpringApplication#setEnvironment()

The following examples show how to use org.springframework.boot.SpringApplication#setEnvironment() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringBootLambdaContainerHandler.java    From aws-serverless-java-container with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize()
        throws ContainerInitializationException {
    Timer.start("SPRINGBOOT_COLD_START");

    SpringApplication app = new SpringApplication(
            springBootInitializer,
            ServerlessServletEmbeddedServerFactory.class,
            SpringBootServletConfigurationSupport.class
    );
    if (springProfiles != null && springProfiles.length > 0) {
        ConfigurableEnvironment springEnv = new StandardEnvironment();
        springEnv.setActiveProfiles(springProfiles);
        app.setEnvironment(springEnv);
    }
    ConfigurableApplicationContext applicationContext = app.run();

    ((ConfigurableWebApplicationContext)applicationContext).setServletContext(getServletContext());
    AwsServletRegistration reg = (AwsServletRegistration)getServletContext().getServletRegistration(DISPATCHER_SERVLET_REGISTRATION_NAME);
    if (reg != null) {
        reg.setLoadOnStartup(1);
    }
    super.initialize();
    initialized = true;
    Timer.stop("SPRINGBOOT_COLD_START");
}
 
Example 2
Source File: PropertiesInvalidInputTest.java    From code-examples with MIT License 5 votes vote down vote up
@BeforeEach
void setup() {
    // create Spring Application dynamically
    application = new SpringApplication(ValidationApplication.class);

    // setting test properties for our Spring Application
    properties = new Properties();

    ConfigurableEnvironment environment = new StandardEnvironment();
    MutablePropertySources propertySources = environment.getPropertySources();
    propertySources.addFirst(new PropertiesPropertySource("application-test", properties));
    application.setEnvironment(environment);
}
 
Example 3
Source File: TestMetaServer.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
@Override
public void doStart() throws Exception{
	
	System.setProperty(DefaultDcMetaCache.MEMORY_META_SERVER_DAO_KEY, configFile);
	System.setProperty("TOTAL_SLOTS", String.valueOf(total_slots));
	
	SpringApplication application = new SpringApplication(TestMetaServer.class);
	application.setBannerMode(Mode.OFF);
	application.setEnvironment(createEnvironment());
	
	context = application.run(new String[]{});
	
	TestZkClient client = context.getBean(TestZkClient.class);
	DefaultZkConfig zkConfig = new DefaultZkConfig();
	zkConfig.setZkSessionTimeoutMillis(zkSessionTimeoutMillis);
	client.setZkConfig(zkConfig);
	client.setZkAddress(zkConnectionStr);

	UnitTestServerConfig config = context.getBean(UnitTestServerConfig.class);
	config.setZkAddress(zkConnectionStr);
	config.setMetaServerId(serverId);
	config.setMetaServerPort(serverPort);
	
	ArrangeTaskTrigger arrangeTaskTrigger = context.getBean(ArrangeTaskTrigger.class);
	arrangeTaskTrigger.setWaitForRestartTimeMills(waitForRestartTimeMills);

	manager = context.getBean(SpringComponentRegistry.class);
	manager.initialize();
	manager.start();
}
 
Example 4
Source File: SpringApplicationStarter.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
public SpringApplicationStarter(Object resource, int port, int maxThreads) {
    application = new SpringApplication(resource);
    application.setBannerMode(Banner.Mode.OFF);
    this.port = port;
    this.maxThreads = maxThreads;
    application.setEnvironment(createEnvironment());
}
 
Example 5
Source File: TaskStartTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
private SpringApplication getTaskApplication(Integer executionId) {
	SpringApplication myapp = new SpringApplication(TaskStartApplication.class);
	Map<String, Object> myMap = new HashMap<>();
	ConfigurableEnvironment environment = new StandardEnvironment();
	MutablePropertySources propertySources = environment.getPropertySources();
	myMap.put("spring.cloud.task.executionid", executionId);
	propertySources
			.addFirst(new MapPropertySource("EnvrionmentTestPropsource", myMap));
	myapp.setEnvironment(environment);
	return myapp;
}