当前位置: 首页>>代码示例>>Java>>正文


Java EmbeddedWebApplicationContext类代码示例

本文整理汇总了Java中org.springframework.boot.context.embedded.EmbeddedWebApplicationContext的典型用法代码示例。如果您正苦于以下问题:Java EmbeddedWebApplicationContext类的具体用法?Java EmbeddedWebApplicationContext怎么用?Java EmbeddedWebApplicationContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


EmbeddedWebApplicationContext类属于org.springframework.boot.context.embedded包,在下文中一共展示了EmbeddedWebApplicationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getBaseUrlForEmbeddedTomcat

import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; //导入依赖的package包/类
/**
 * /!\ Work only if application run on embedded Tomcat server
 *
 * @return
 * @throws Exception
 */
public static String getBaseUrlForEmbeddedTomcat() throws Exception {

    // get embedded tomcat
    EmbeddedWebApplicationContext appContext = (EmbeddedWebApplicationContext) new ApplicationContextProvider().getApplicationContext();
    Tomcat tomcat = ((TomcatEmbeddedServletContainer) appContext.getEmbeddedServletContainer()).getTomcat();
    Connector connector = tomcat.getConnector();

    // compose address
    String scheme = connector.getScheme();
    String hostName = tomcat.getHost().getName();
    int port = connector.getPort();
    String contextPath = appContext.getServletContext().getContextPath();

    return scheme + "://" + hostName + ":" + port + contextPath;
}
 
开发者ID:remipassmoilesel,项目名称:simple-hostel-management,代码行数:22,代码来源:Utils.java

示例2: getPortFile

import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; //导入依赖的package包/类
/**
 * Return the actual port file that should be written for the given application
 * context. The default implementation builds a file from the source file and the
 * application context namespace.
 * @param applicationContext the source application context
 * @return the file that should be written
 */
protected File getPortFile(EmbeddedWebApplicationContext applicationContext) {
	String contextName = applicationContext.getNamespace();
	if (StringUtils.isEmpty(contextName)) {
		return this.file;
	}
	String name = this.file.getName();
	String extension = StringUtils.getFilenameExtension(this.file.getName());
	name = name.substring(0, name.length() - extension.length() - 1);
	if (isUpperCase(name)) {
		name = name + "-" + contextName.toUpperCase();
	}
	else {
		name = name + "-" + contextName.toLowerCase();
	}
	if (StringUtils.hasLength(extension)) {
		name = name + "." + extension;
	}
	return new File(this.file.getParentFile(), name);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:27,代码来源:EmbeddedServerPortFileWriter.java

示例3: registerWithSimpleWebApp

import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; //导入依赖的package包/类
@Test
public void registerWithSimpleWebApp() throws Exception {
	this.context = new SpringApplicationBuilder()
			.sources(EmbeddedServletContainerAutoConfiguration.class,
					ServerPropertiesAutoConfiguration.class,
					DispatcherServletAutoConfiguration.class,
					JmxAutoConfiguration.class,
					SpringApplicationAdminJmxAutoConfiguration.class)
			.run("--" + ENABLE_ADMIN_PROP, "--server.port=0");
	assertThat(this.context).isInstanceOf(EmbeddedWebApplicationContext.class);
	assertThat(this.mBeanServer.getAttribute(createDefaultObjectName(),
			"EmbeddedWebApplication")).isEqualTo(Boolean.TRUE);
	int expected = ((EmbeddedWebApplicationContext) this.context)
			.getEmbeddedServletContainer().getPort();
	String actual = getProperty(createDefaultObjectName(), "local.server.port");
	assertThat(actual).isEqualTo(String.valueOf(expected));
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:SpringApplicationAdminJmxAutoConfigurationTests.java

示例4: afterSingletonsInstantiated

import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; //导入依赖的package包/类
@Override
public void afterSingletonsInstantiated() {
	ManagementServerPort managementPort = ManagementServerPort.DIFFERENT;
	if (this.applicationContext instanceof WebApplicationContext) {
		managementPort = ManagementServerPort
				.get(this.applicationContext.getEnvironment(), this.beanFactory);
	}
	if (managementPort == ManagementServerPort.DIFFERENT) {
		if (this.applicationContext instanceof EmbeddedWebApplicationContext
				&& ((EmbeddedWebApplicationContext) this.applicationContext)
						.getEmbeddedServletContainer() != null) {
			createChildManagementContext();
		}
		else {
			logger.warn("Could not start embedded management container on "
					+ "different port (management endpoints are still available "
					+ "through JMX)");
		}
	}
	if (managementPort == ManagementServerPort.SAME && this.applicationContext
			.getEnvironment() instanceof ConfigurableEnvironment) {
		addLocalManagementPortPropertyAlias(
				(ConfigurableEnvironment) this.applicationContext.getEnvironment());
	}
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:26,代码来源:EndpointWebMvcAutoConfiguration.java

示例5: getServicePort

import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; //导入依赖的package包/类
private Integer getServicePort(EmbeddedWebApplicationContext webContext)
{
   Integer port = null;
   if (webContext != null)
   {
      final EmbeddedServletContainer container = webContext.getEmbeddedServletContainer();

      if (container instanceof TomcatEmbeddedServletContainer)
      {
         // Work around an issue with the tomcat container, which uses the local port
         // as the port (-1) instead of the registered port
         port = ((TomcatEmbeddedServletContainer) container).getTomcat().getConnector().getPort();
      }
      else
      {
         port = container.getPort();
      }
   }
   return port;
}
 
开发者ID:HomeAdvisor,项目名称:Kafdrop,代码行数:21,代码来源:ServiceDiscoveryConfiguration.java

示例6: registerWithSimpleWebApp

import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; //导入依赖的package包/类
@Test
public void registerWithSimpleWebApp() throws Exception {
	this.context = new SpringApplicationBuilder()
			.sources(EmbeddedServletContainerAutoConfiguration.class,
					ServerPropertiesAutoConfiguration.class,
					DispatcherServletAutoConfiguration.class,
					JmxAutoConfiguration.class,
					SpringApplicationAdminJmxAutoConfiguration.class)
			.run("--" + ENABLE_ADMIN_PROP, "--server.port=0");
	assertTrue(this.context instanceof EmbeddedWebApplicationContext);
	assertEquals(true, this.mBeanServer.getAttribute(createDefaultObjectName(),
			"EmbeddedWebApplication"));
	int expected = ((EmbeddedWebApplicationContext) this.context)
			.getEmbeddedServletContainer().getPort();
	String actual = getProperty(createDefaultObjectName(), "local.server.port");
	assertEquals(String.valueOf(expected), actual);
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:18,代码来源:SpringApplicationAdminJmxAutoConfigurationTests.java

示例7: main

import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; //导入依赖的package包/类
/**
 * spring boot 服务主入口
 *
 * @param args
 */
public static void main(String[] args) {
    ApplicationContext context = SpringApplication.run(Bootstrap.class, args);
    if (context instanceof EmbeddedWebApplicationContext) {
        int port = ((EmbeddedWebApplicationContext) context).getEmbeddedServletContainer().getPort();
        String contextPath = context.getApplicationName();
        String url = String.format(Locale.US, "http://localhost:%d%s", port, contextPath);
        if (log.isInfoEnabled()) {
            //提示项目用到的相关配置文件
            log.info(" =========== ${user.dir}={} ===========  ", System.getProperty("user.dir"));
            log.info(" =========== ${java.io.tmpdir}={} ===========  ", System.getProperty("java.io.tmpdir"));

            String dashes = "------------------------------------------------------------------------";
            log.info("Access URLs:\n{}\n\tLocal: \t\t{}\n{}", dashes, url, dashes);
        }
    }
}
 
开发者ID:cyzaoj,项目名称:mywx,代码行数:22,代码来源:Bootstrap.java

示例8: metrics

import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; //导入依赖的package包/类
@Bean
public TomcatMetrics metrics(ApplicationContext applicationContext) {
    Manager manager = null;
    if (applicationContext instanceof EmbeddedWebApplicationContext) {
        manager = getManagerFromContext((EmbeddedWebApplicationContext) applicationContext);
    }
    return new TomcatMetrics(manager, Collections.emptyList());
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:9,代码来源:TomcatMetricsConfiguration.java

示例9: getManagerFromContext

import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; //导入依赖的package包/类
private Manager getManagerFromContext(EmbeddedWebApplicationContext applicationContext) {
    EmbeddedServletContainer embeddedServletContainer = applicationContext.getEmbeddedServletContainer();
    if (embeddedServletContainer instanceof TomcatEmbeddedServletContainer) {
        return getManagerFromContainer((TomcatEmbeddedServletContainer) embeddedServletContainer);
    }
    return null;
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:8,代码来源:TomcatMetricsConfiguration.java

示例10: main

import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; //导入依赖的package包/类
public static void main(String[] args) {
    ApplicationContext context = SpringApplication.run(Application.class, args);
    if (log.isInfoEnabled() && context instanceof EmbeddedWebApplicationContext) {
        int port = ((EmbeddedWebApplicationContext) context).getEmbeddedServletContainer().getPort();
        String contextPath = context.getApplicationName();
        final String dashes = Strings.repeat("-", 72);
        log.info("Access URLs:\n{}\n\tLocal:\t\thttp://localhost:{}{}\n{}", dashes, port, contextPath, dashes);
    }
}
 
开发者ID:zjnu-acm,项目名称:judge,代码行数:10,代码来源:Application.java

示例11: afterSingletonsInstantiated

import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; //导入依赖的package包/类
@Override
public void afterSingletonsInstantiated() {
	ManagementServerPort managementPort = ManagementServerPort.DIFFERENT;
	if (this.applicationContext instanceof WebApplicationContext) {
		managementPort = ManagementServerPort
				.get(this.applicationContext.getEnvironment(), this.beanFactory);
	}
	if (managementPort == ManagementServerPort.DIFFERENT) {
		if (this.applicationContext instanceof EmbeddedWebApplicationContext
				&& ((EmbeddedWebApplicationContext) this.applicationContext)
						.getEmbeddedServletContainer() != null) {
			createChildManagementContext();
		}
		else {
			logger.warn("Could not start embedded management container on "
					+ "different port (management endpoints are still available "
					+ "through JMX)");
		}
	}
	if (managementPort == ManagementServerPort.SAME) {
		if (new RelaxedPropertyResolver(this.applicationContext.getEnvironment(),
				"management.ssl.").getProperty("enabled") != null) {
			throw new IllegalStateException(
					"Management-specific SSL cannot be configured as the management "
							+ "server is not listening on a separate port");
		}
		if (this.applicationContext
				.getEnvironment() instanceof ConfigurableEnvironment) {
			addLocalManagementPortPropertyAlias(
					(ConfigurableEnvironment) this.applicationContext
							.getEnvironment());
		}
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:35,代码来源:EndpointWebMvcAutoConfiguration.java

示例12: metrics

import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; //导入依赖的package包/类
@Override
public Collection<Metric<?>> metrics() {
	if (this.applicationContext instanceof EmbeddedWebApplicationContext) {
		Manager manager = getManager(
				(EmbeddedWebApplicationContext) this.applicationContext);
		if (manager != null) {
			return metrics(manager);
		}
	}
	return Collections.emptySet();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:TomcatPublicMetrics.java

示例13: getManager

import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; //导入依赖的package包/类
private Manager getManager(EmbeddedWebApplicationContext applicationContext) {
	EmbeddedServletContainer embeddedServletContainer = applicationContext
			.getEmbeddedServletContainer();
	if (embeddedServletContainer instanceof TomcatEmbeddedServletContainer) {
		return getManager((TomcatEmbeddedServletContainer) embeddedServletContainer);
	}
	return null;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:TomcatPublicMetrics.java

示例14: mockEvent

import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; //导入依赖的package包/类
private EmbeddedServletContainerInitializedEvent mockEvent(String name, int port) {
	EmbeddedWebApplicationContext applicationContext = mock(
			EmbeddedWebApplicationContext.class);
	EmbeddedServletContainer source = mock(EmbeddedServletContainer.class);
	given(applicationContext.getNamespace()).willReturn(name);
	given(source.getPort()).willReturn(port);
	EmbeddedServletContainerInitializedEvent event = new EmbeddedServletContainerInitializedEvent(
			applicationContext, source);
	return event;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:11,代码来源:EmbeddedServerPortFileWriterTests.java

示例15: getPropertyName

import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; //导入依赖的package包/类
protected String getPropertyName(EmbeddedWebApplicationContext context) {
	String name = context.getNamespace();
	if (StringUtils.isEmpty(name)) {
		name = "server";
	}
	return "local." + name + ".port";
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:8,代码来源:ServerPortInfoApplicationContextInitializer.java


注:本文中的org.springframework.boot.context.embedded.EmbeddedWebApplicationContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。