类org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext源码实例Demo

下面列出了怎么用org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Moss   文件: DiscoveryClientRegistrationInvoker.java
@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())
        );
    }
}
 
源代码2 项目: spring-fu   文件: Jafu.java
/**
 * 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();
		}
	};
}
 
@Test
public void applicationContextLoadsAndIsCorrectType() {

	assertThat(this.applicationContext).isNotNull();
	assertThat(this.applicationContext).isNotInstanceOf(WebApplicationContext.class);
	assertThat(this.applicationContext).isNotInstanceOf(ServletWebServerApplicationContext.class);
}
 
源代码4 项目: armeria   文件: HelloConfiguration.java
/**
 * 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();
}
 
源代码5 项目: spring-init   文件: FunctionalInstallerListener.java
@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);
			}
		}
	}
}
 
源代码6 项目: armeria   文件: HelloConfiguration.java
/**
 * 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();
}
 
源代码7 项目: armeria   文件: HelloConfiguration.java
/**
 * 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));
}
 
 类所在包
 类方法
 同包方法