org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext Java Examples

The following examples show how to use org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext. 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: DiscoveryClientRegistrationInvoker.java    From Moss with Apache License 2.0 5 votes vote down vote up
@Override
public void customize(ConfigurableApplicationContext context) {
    if(context instanceof ServletWebServerApplicationContext
            && !AdminEndpointApplicationRunListener.isEmbeddedServletServer(context.getEnvironment())) {
        MetaDataProvider metaDataProvider = context.getBean(MetaDataProvider.class);
        WebServer webServer = new WebServer() {
            @Override
            public void start() throws WebServerException {

            }

            @Override
            public void stop() throws WebServerException {

            }

            @Override
            public int getPort() {
                return metaDataProvider.getServerPort();
            }
        };
        context.publishEvent(
                new ServletWebServerInitializedEvent(
                        webServer,
                        new ServletWebServerApplicationContext())
        );
    }
}
 
Example #2
Source File: Jafu.java    From spring-fu with Apache License 2.0 5 votes vote down vote up
/**
 * Declare a Servlet-based web {@link ApplicationDsl application} that allows to configure a Spring Boot
 * application using Jafu DSL and functional bean registration.
 */
public static JafuApplication webApplication(Consumer<ApplicationDsl> dsl) {
	return new JafuApplication(new ApplicationDsl(dsl)) {
		@Override
		protected ConfigurableApplicationContext createContext() {
			return new ServletWebServerApplicationContext();
		}
	};
}
 
Example #3
Source File: InitializerApplicationSmokeTests.java    From spring-boot-data-geode with Apache License 2.0 5 votes vote down vote up
@Test
public void applicationContextLoadsAndIsCorrectType() {

	assertThat(this.applicationContext).isNotNull();
	assertThat(this.applicationContext).isNotInstanceOf(WebApplicationContext.class);
	assertThat(this.applicationContext).isNotInstanceOf(ServletWebServerApplicationContext.class);
}
 
Example #4
Source File: HelloConfiguration.java    From armeria with Apache License 2.0 5 votes vote down vote up
/**
 * Extracts a Tomcat {@link Connector} from Spring webapp context.
 */
public static Connector getConnector(ServletWebServerApplicationContext applicationContext) {
    final TomcatWebServer container = (TomcatWebServer) applicationContext.getWebServer();

    // Start the container to make sure all connectors are available.
    container.start();
    return container.getTomcat().getConnector();
}
 
Example #5
Source File: FunctionalInstallerListener.java    From spring-init with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(ApplicationEvent event) {
	if (event instanceof ApplicationContextInitializedEvent) {
		ApplicationContextInitializedEvent initialized = (ApplicationContextInitializedEvent) event;
		ConfigurableApplicationContext context = initialized.getApplicationContext();
		if (!(context instanceof GenericApplicationContext)) {
			throw new IllegalStateException("ApplicationContext must be a GenericApplicationContext");
		}
		if (!isEnabled(context.getEnvironment())) {
			return;
		}
		GenericApplicationContext generic = (GenericApplicationContext) context;
		ConditionService conditions = initialize(generic);
		functional(generic, conditions);
		apply(generic, initialized.getSpringApplication(), conditions);
	}
	else if (event instanceof ApplicationEnvironmentPreparedEvent) {
		ApplicationEnvironmentPreparedEvent prepared = (ApplicationEnvironmentPreparedEvent) event;
		if (!isEnabled(prepared.getEnvironment())) {
			return;
		}
		logger.info("Preparing application context");
		SpringApplication application = prepared.getSpringApplication();
		findInitializers(application);
		WebApplicationType type = getWebApplicationType(application, prepared.getEnvironment());
		Class<?> contextType = getApplicationContextType(application);
		if (type == WebApplicationType.NONE) {
			if (contextType == AnnotationConfigApplicationContext.class || contextType == null) {
				application.setApplicationContextClass(GenericApplicationContext.class);
			}
		}
		else if (type == WebApplicationType.REACTIVE) {
			if (contextType == AnnotationConfigReactiveWebApplicationContext.class || contextType == null) {
				application.setApplicationContextClass(ReactiveWebServerApplicationContext.class);
			}
		}
		else if (type == WebApplicationType.SERVLET) {
			if (contextType == AnnotationConfigServletWebServerApplicationContext.class || contextType == null) {
				application.setApplicationContextClass(ServletWebServerApplicationContext.class);
			}
		}
	}
}
 
Example #6
Source File: HelloConfiguration.java    From armeria with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a new {@link HealthChecker} that marks the server as unhealthy when Tomcat becomes unavailable.
 */
@Bean
public HealthChecker tomcatConnectorHealthChecker(ServletWebServerApplicationContext applicationContext) {
    final Connector connector = getConnector(applicationContext);
    return () -> connector.getState().isAvailable();
}
 
Example #7
Source File: HelloConfiguration.java    From armeria with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a new {@link TomcatService} that redirects the incoming requests to the Tomcat instance
 * provided by Spring Boot.
 */
@Bean
public TomcatService tomcatService(ServletWebServerApplicationContext applicationContext) {
    return TomcatService.of(getConnector(applicationContext));
}