過去2日間のプロジェクトはgitにアップロードされていませんでしたが、今日もコードのコーディングを続けたところ、奇妙な問題が発生しました。
コードが2日間移動しなかった場合、このような問題はどのように発生しますか?私は非常に落ち込んでいます。。。。。。。。。。。。。。。。。。
問題:プロジェクトを開始するとき
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202) [spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at com.dataGovernance.DataGovernanceApplication.main(DataGovernanceApplication.java:14) [classes/:?]
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:202) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:178) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:152) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
... 8 more;
上記の質問は明らかに次のとおりです。ServletWebServerFactoryBean
がないためですが、なぜこのような問題が発生するのでしょうか。????
コードは次のように表示されます。
@SpringBootApplication
@EnableScheduling
public class DataGovernanceApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(DataGovernanceApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(DataGovernanceApplication.class);
}
}
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
@SpringBootApplicationに注釈を付け、注釈を付けます。SpringBootServletInitializer
クラスを継承し、configureメソッドを書き直します。pom
ファイルの依存関係もインポートされます。
Baiduからもたくさん検索しましたが、基本的には上記の3つの問題
であり、あいまいなSpringBootServletInitializerのソースコードも調べました。
最後に試したメソッドは、スタートアップクラスのクラス名とスタートアップメソッドのメソッド名を変更しましたが、不思議なことに、スタートアップが成功し、エラーが報告されませんでした。。。。。。
になる
public class DataGovernanaceApplication extends SpringBootServletInitializer
何度か試しましたが、クラス名を直接変更するだけでは不十分です。まずメソッド名を変更してから、型を変更してください。
プロジェクトが急いでいるため、このコードを最初に実行することしかできず、後で解決します。
ここで、皆さん、問題が何かご存知の方は、説明してください、ありがとうございます!!!