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


Java ConfigurableApplicationContext.getEnvironment方法代码示例

本文整理汇总了Java中org.springframework.context.ConfigurableApplicationContext.getEnvironment方法的典型用法代码示例。如果您正苦于以下问题:Java ConfigurableApplicationContext.getEnvironment方法的具体用法?Java ConfigurableApplicationContext.getEnvironment怎么用?Java ConfigurableApplicationContext.getEnvironment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.context.ConfigurableApplicationContext的用法示例。


在下文中一共展示了ConfigurableApplicationContext.getEnvironment方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.springframework.context.ConfigurableApplicationContext; //导入方法依赖的package包/类
public static void main(String[] args) {
    final SpringApplication app = new SpringApplication(Application.class);
    // save the pid into a file...
    app.addListeners(new ApplicationPidFileWriter("smarti.pid"));

    final ConfigurableApplicationContext context = app.run(args);
    final ConfigurableEnvironment env = context.getEnvironment();

    try {
        //http://localhost:8080/admin/index.html
        final URI uri = new URI(
                (env.getProperty("server.ssl.enabled", Boolean.class, false) ? "https" : "http"),
                null,
                (env.getProperty("server.address", "localhost")),
                (env.getProperty("server.port", Integer.class, 8080)),
                (env.getProperty("server.context-path", "/")).replaceAll("//+", "/"),
                null, null);

        log.info("{} started: {}",
                env.getProperty("server.display-name", context.getDisplayName()),
                uri);
    } catch (URISyntaxException e) {
        log.warn("Could not build launch-url: {}", e.getMessage());
    }
}
 
开发者ID:redlink-gmbh,项目名称:smarti,代码行数:26,代码来源:Application.java

示例2: run

import org.springframework.context.ConfigurableApplicationContext; //导入方法依赖的package包/类
public void run(Class clazz, String[] args) {
        SpringApplication springApplication = new SpringApplication(clazz);
//        springApplication.addListeners(new ApplicationPidFileWriter("application.pid"));
        ConfigurableApplicationContext ctx = springApplication.run(args);
        Environment env = ctx.getEnvironment();
        if (env.acceptsProfiles(ProfileConstant.RT_SCRIPT)) {
            if (args.length > 0) {
                String shellClass = args[0];
                ScriptInterface script = (ScriptInterface) ctx.getBean(shellClass);
                if (null != script) {
                    try {
                        if (args.length > 1) {
                            script.run(Arrays.copyOfRange(args, 1, args.length));
                        } else {
                            script.run(new String[]{});
                        }
                    } catch (Exception e) {
                        scriptLogger.error("error occur", e);
                    }
                }
            }
        }
    }
 
开发者ID:superkoh,项目名称:k-framework,代码行数:24,代码来源:KApplication.java

示例3: initialize

import org.springframework.context.ConfigurableApplicationContext; //导入方法依赖的package包/类
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
	this.environment = applicationContext.getEnvironment();
	this.resourceLoader = applicationContext;
	this.profile = Profiles.getActiveProfile(environment);

	NameLocationPair pair = getPropertySourceFirst();
	if(pair != null){
		addPropertySource(pair.getName(),pair.getLocation());
	}
	addPropertySource(OVERRIDE_PROPERTIES_SOURCE_NAME, System.getProperty(OVERRIDE_PROPERTIES_SOURCE_LOCATION));
	addPropertySource(PROJECT_PROPERTIES_SOURCE_NAME, PROJECT_PROPERTIES_SOURCE_LOCATION);
	addPropertySource(PROJECT_PROPERTIES_SOURCE_DEFAULT_NAME, PROJECT_PROPERTIES_SOURCE_DEFAULT_LOCATION);
	addPropertySource(PARENT_PROPERTIES_SOURCE_NAME, PARENT_PROPERTIES_SOURCE_LOCATION);
	addPropertySource(PARENT_PROPERTIES_SOURCE_DEFAULT_NAME, PARENT_PROPERTIES_SOURCE_DEFAULT_LOCATION);

	LogbackConfig.init(LOGBACK_CONFIG_LOCATION);
}
 
开发者ID:profullstack,项目名称:spring-seed,代码行数:19,代码来源:ProfileApplicationContextInitializer.java

示例4: main

import org.springframework.context.ConfigurableApplicationContext; //导入方法依赖的package包/类
/**
 * Main method, used to run the application.
 *
 * @param args the command line arguments
 * @throws UnknownHostException if the local host name could not be resolved into an address
 */
public static void main(String[] args) throws UnknownHostException {
    SpringApplication app = new SpringApplication(OperonCloudPlatformApp.class);
    DefaultProfileUtil.addDefaultProfile(app);
    ConfigurableApplicationContext ctx= app.run(args);
    Environment env = ctx.getEnvironment();
    String protocol = "http";
    if (env.getProperty("server.ssl.key-store") != null) {
        protocol = "https";
    }
    log.info("\n----------------------------------------------------------\n\t" +
            "Application '{}' is running! Access URLs:\n\t" +
            "Local: \t\t{}://localhost:{}\n\t" +
            "External: \t{}://{}:{}\n\t" +
            "Profile(s): \t{}\n----------------------------------------------------------",
        env.getProperty("spring.application.name"),
        protocol,
        env.getProperty("server.port"),
        protocol,
        InetAddress.getLocalHost().getHostAddress(),
        env.getProperty("server.port"),
        env.getActiveProfiles());

    if(Arrays.asList(env.getActiveProfiles()).contains("dev") || Arrays.asList(env.getActiveProfiles()).contains("prod")) {
        // add sample data if none exists
        verifyAndImportPlants(ctx);
    }
}
 
开发者ID:AppertaFoundation,项目名称:Code4Health-Platform,代码行数:34,代码来源:OperonCloudPlatformApp.java

示例5: initialize

import org.springframework.context.ConfigurableApplicationContext; //导入方法依赖的package包/类
@Override
public void initialize(final ConfigurableApplicationContext applicationContext) {
    final ConfigurableEnvironment environment = applicationContext.getEnvironment();
    environment.getPropertySources().addFirst(new MapPropertySource("test-source",
            Collections.singletonMap("verifier.service", "localhost:" + wireMock.port())));
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:7,代码来源:BaseITCase.java


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