【问题标题】:generating a working war file with maven for a spring-boot web application使用 maven 为 spring-boot Web 应用程序生成一个工作战争文件
【发布时间】:2015-03-05 17:14:32
【问题描述】:

我们有一个 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

我尝试在maven-war-plugin 的配置中添加mainClass 指令,但无济于事。

【问题讨论】:

  • 你使用Eclipse开发项目吗?如果是这样,请尝试右键单击项目 -> 导出。
  • 您是否配置了带有 @SpringApplication 注释类的 SpringBootServletInitializer 来启动您的应用程序?
  • @dunni 我没有@SpringApplication 类(我什至在任何spring 文档中都没有找到这样的注释),我有一个带有main(args) 函数的类,它可以执行SpringApplication app = new SpringApplication(App.class); 和app.run(args); .对于 maven 嵌入式 tomcat,我确实有一个扩展 SpringBootServletInitializer 的类,但不需要在任何地方声明它。我会调查的。

标签: java spring maven tomcat


【解决方案1】:

我按照邓尼的建议设法发动了一场战争。

基本上,我需要在扩展SpringBootServletInitializer 的类上添加@SpringBootApplication 注释,并覆盖其configure 方法。

所以我的代码的差异是这样的:

+@SpringBootApplication
 public class WebAppInitializer extends SpringBootServletInitializer {

+        @Override
+       protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
+               return application.sources(App.class);
+       }

我仍然有一个错误,但只是在春季开始之后,但我会在另一个问题中询问。

【讨论】:

    猜你喜欢
    • 2017-12-21
    • 2014-12-31
    • 2018-06-07
    • 2018-01-30
    • 2017-12-03
    • 1970-01-01
    • 2017-03-11
    • 2010-09-24
    • 1970-01-01
    相关资源
    最近更新 更多