![](/img/trans.png)
[英]Deploying a spring-boot application as a war file on a dedicated tomcat is not working
[英]generating a working war file with maven for a spring-boot web application
我們有一個maven管理的spring-boot應用程序,我們現在需要使用WAR文件在tomcat中部署。 在開發過程中,我們使用maven使用以下命令啟動嵌入式tomcat:
mvn -D"-classpath %classpath package.path.App" -D"exec.executable=java" process-classes org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
我可以通過運行mvn war:war
來構建war文件,但如果我嘗試部署生成的war,則會產生錯誤:
SEVERE: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext
...
Caused by: java.lang.IllegalStateException: No SpringApplication sources have been defined. Either override the configure method or add an @Configuration annotation
我嘗試將一個mainClass
指令添加到maven-war-plugin
的配置中,但無濟於事。
根據鄧尼的建議,我設法建立了一場戰爭。
基本上,我需要在擴展SpringBootServletInitializer
的類上添加@SpringBootApplication
注釋,並覆蓋其configure
方法。
所以代碼的差異就像:
+@SpringBootApplication
public class WebAppInitializer extends SpringBootServletInitializer {
+ @Override
+ protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
+ return application.sources(App.class);
+ }
我仍然有一個錯誤,但只是在春天開始后,但我會在另一個問題中詢問。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.