下面列出了org.springframework.boot.SpringApplication#setWebEnvironment ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void main(String[] args) throws Exception {
// the code must execute before spring start
JarFile bootJarFile = BootJarLaucherUtils.getBootJarFile();
if (bootJarFile != null) {
BootJarLaucherUtils.unpackBootLibs(bootJarFile);
log.debug("the temp tac lib folder:{}", BootJarLaucherUtils.getTempUnpackFolder());
}
SpringApplication springApplication = new SpringApplication(ContainerApplication.class);
springApplication.setWebEnvironment(true);
springApplication.setBannerMode(Banner.Mode.OFF);
springApplication.addListeners(new ApplicationListener<ApplicationEnvironmentPreparedEvent>() {
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
CodeLoadService.changeClassLoader(event.getEnvironment());
}
});
springApplication.run(args);
}
@Test
public void testAllSet() {
SpringApplication app = new SpringApplication(TestConfiguration.class);
app.setWebEnvironment(false);
ConfigurableApplicationContext context = app
.run(new String[] { "--spring.net.hostdiscovery.pointToPoint=true",
"--spring.net.hostdiscovery.loopback=true",
"--spring.net.hostdiscovery.preferInterface=lxcbr",
"--spring.net.hostdiscovery.matchIpv4=192.168.0.0/24",
"--spring.net.hostdiscovery.matchInterface=eth0" });
HostInfoDiscoveryProperties properties = context.getBean(HostInfoDiscoveryProperties.class);
assertThat(properties, notNullValue());
assertThat(properties.isPointToPoint(), is(true));
assertThat(properties.isLoopback(), is(true));
assertThat(properties.getPreferInterface(), notNullValue());
assertThat(properties.getPreferInterface().size(), is(1));
assertThat(properties.getMatchIpv4(), is("192.168.0.0/24"));
assertThat(properties.getMatchInterface(), is("eth0"));
context.close();
}
@Test
public void testErrorTable1() {
SpringApplication app = new SpringApplication(TestConfiguration.class);
app.setWebEnvironment(false);
ConfigurableApplicationContext context = app
.run(new String[] { "--gpfdist.errorTable=myerror",
"--gpfdist.segmentRejectLimit=1",
"--gpfdist.segmentRejectType=ROWS" });
GpfdistSinkProperties properties = context.getBean(GpfdistSinkProperties.class);
assertThat(properties, notNullValue());
assertThat(properties.getErrorTable(), is("myerror"));
assertThat(properties.getSegmentRejectLimit(), is("1"));
assertThat(properties.getSegmentRejectType(), is(SegmentRejectType.ROWS));
context.close();
}
@Test
public void testErrorTable2() {
SpringApplication app = new SpringApplication(TestConfiguration.class);
app.setWebEnvironment(false);
ConfigurableApplicationContext context = app
.run(new String[] { "--gpfdist.errorTable=myerror",
"--gpfdist.segmentRejectLimit=1",
"--gpfdist.segmentRejectType=percent" });
GpfdistSinkProperties properties = context.getBean(GpfdistSinkProperties.class);
assertThat(properties, notNullValue());
assertThat(properties.getErrorTable(), is("myerror"));
assertThat(properties.getSegmentRejectLimit(), is("1"));
assertThat(properties.getSegmentRejectType(), is(SegmentRejectType.PERCENT));
context.close();
}
public static void main(String[] args) {
SpringApplication application = new SpringApplication();
String command = new CliCommand(args).get();
OsiamHome osiamHome = new OsiamHome();
if ("initHome".equals(command)) {
application.setSources(Collections.<Object>singleton(InitHome.class));
application.setWebEnvironment(false);
} else if ("migrateDb".equals(command)) {
application.setSources(Collections.<Object>singleton(MigrateDb.class));
application.setWebEnvironment(false);
osiamHome.shouldInitializeHome(false);
} else {
application.setSources(Collections.<Object>singleton(Osiam.class));
}
application.addListeners(osiamHome);
application.setDefaultProperties(DEFAULT_PROPERTIES);
application.run(args);
}
/**
* Application entry point.
*
* @param args
*/
public static void main(String[] args) {
SpringApplication app = new SpringApplication(App.class);
app.setBannerMode(Banner.Mode.OFF);
app.setWebEnvironment(false);
app.run(args);
}
@Test
public void testPreferOne() {
SpringApplication app = new SpringApplication(TestConfiguration.class);
app.setWebEnvironment(false);
ConfigurableApplicationContext context = app
.run(new String[] { "--spring.net.hostdiscovery.preferInterface=lxcbr" });
HostInfoDiscoveryProperties properties = context.getBean(HostInfoDiscoveryProperties.class);
assertThat(properties, notNullValue());
assertThat(properties.getPreferInterface(), notNullValue());
assertThat(properties.getPreferInterface().size(), is(1));
context.close();
}
@Test
public void testPreferTwo() {
SpringApplication app = new SpringApplication(TestConfiguration.class);
app.setWebEnvironment(false);
ConfigurableApplicationContext context = app
.run(new String[] { "--spring.net.hostdiscovery.preferInterface=lxcbr,foo" });
HostInfoDiscoveryProperties properties = context.getBean(HostInfoDiscoveryProperties.class);
assertThat(properties, notNullValue());
assertThat(properties.getPreferInterface(), notNullValue());
assertThat(properties.getPreferInterface().size(), is(2));
assertThat(properties.getPreferInterface(), containsInAnyOrder("lxcbr", "foo"));
context.close();
}
@Test
public void testNullString() {
SpringApplication app = new SpringApplication(TestConfiguration.class);
app.setWebEnvironment(false);
ConfigurableApplicationContext context = app
.run(new String[] { "--gpfdist.nullString=mynullstring" });
GpfdistSinkProperties properties = context.getBean(GpfdistSinkProperties.class);
assertThat(properties, notNullValue());
assertThat(properties.getNullString(), is("mynullstring"));
context.close();
}
public UserRegistrationSteps() {
super();
SpringApplication application = new SpringApplication(
RegistrationApplication.class);
application.setWebEnvironment(false);
AutowiredAnnotationBeanPostProcessor autowiredAnnotationBeanPostProcessor = new AutowiredAnnotationBeanPostProcessor();
autowiredAnnotationBeanPostProcessor.setBeanFactory(application.run()
.getBeanFactory());
autowiredAnnotationBeanPostProcessor.processInjection(this);
}
public UserRegistrationSteps() {
super();
SpringApplication application = new SpringApplication(
RegistrationApplication.class);
application.setWebEnvironment(false);
AutowiredAnnotationBeanPostProcessor autowiredAnnotationBeanPostProcessor = new AutowiredAnnotationBeanPostProcessor();
autowiredAnnotationBeanPostProcessor.setBeanFactory(application.run()
.getBeanFactory());
autowiredAnnotationBeanPostProcessor.processInjection(this);
}
public static void main(String[] args) throws Exception {
SpringApplication app = new SpringApplication(MonitoringApplication.class);
app.setWebEnvironment(false);
ConfigurableApplicationContext ctx = app.run(args);
MonitoringApplication myApp = ctx.getBean(MonitoringApplication.class);
myApp.testMonitoring();
ctx.close();
}
public static void main(String[] args) {
SpringApplication app = new SpringApplication(MyApplication.class);
app.setWebEnvironment(false);
ConfigurableApplicationContext ctx = app.run(args);
MyApplication myApp = ctx.getBean(MyApplication.class);
myApp.playConsoleGame();
ctx.close();
}
public static void main(String[] args) {
SpringApplication application = new SpringApplication(Starter.class);
// To disabled web environment, change `true` to `false`
application.setWebEnvironment(true);
application.run(args);
}
public static void main(String[] args) {
SpringApplication app = new SpringApplication(TalkGrpcApplication.class);
app.setWebEnvironment(false);
app.run(args);
}
public static void main(String[] args) {
SpringApplication application = new SpringApplication(
OperationsLoggingApplication.class);
application.setWebEnvironment(false);
application.run(args);
}