gpt4 book ai didi

java - 扩展SpringBootInitializer时,为什么要覆盖configure方法?

转载 作者:行者123 更新时间:2023-11-29 04:27:57 24 4
gpt4 key购买 nike

众所周知,要发布 Spring Boot war ,我们应该扩展 SpringBootServletInitializer,然后重写配置方法,如下所示:

@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(DemoApplication.class);
}
}

我把重写的配置方法注释掉,然后应用程序运行无异常。那我为什么要重写configure方法,它的用法是什么?

最佳答案

The main method initializes an application context via a factory method inside SpringApplication. It is using Spring Boot’s SpringApplication.run() method to launch the application. The configure method inherited from SpringBootServletInitializer does essentially the same but only when deployed as a war file.

关于java - 扩展SpringBootInitializer时,为什么要覆盖configure方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45264283/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com