本文整理汇总了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());
}
}
示例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);
}
}
}
}
}
示例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);
}
示例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);
}
}
示例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())));
}