我喜欢spring boot,但无法弄清楚/如何找到它:我有可执行的spring应用程序。我需要applicationContext,做一些事情,然后启动“ webPart”(REST API)。是否可以告诉spring“不要自动启动码头,我自己启动”,还是我需要自己编写应用程序?
我想做这样的事情。有人知道吗?
@SpringApplication
public class App {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(App.class, args);
try {
doSth(ctx);
startWeb();
} catch(Exception e) {
clean();
}
}
}
编辑:我想使用“ web-part”,但稍后,当我决定(fe异常不会引发...)。我根本不想阻止使用网络上下文。
一种方法是销毁第一个上下文(已禁用Web),然后在启用Web的情况下启动新上下文。
ConfigurableApplicationContext ctx = new SpringApplicationBuilder(Application.class).web(false).run(args);
try {
doSomething(ctx);
} catch (Exception e){
//abort
} finally {
ctx.close();
}
//New context has web enabled.
ctx = new SpringApplicationBuilder(Application.class).run(args);
doSomething(ctx);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句