3

We have a maven-managed spring-boot application that we now need to deploy in tomcat using a WAR file. During development, we used maven to start an embedded tomcat with the command:

mvn -D"-classpath %classpath package.path.App" -D"exec.executable=java" process-classes org.codehaus.mojo:exec-maven-plugin:1.2.1:exec 

I can build a war file by running mvn war:war, but if I try to deploy the resulting war, an error is produced:

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 

I tried adding a mainClass directive to the maven-war-plugin's configuration, but to no avail.

3
  • Do you use Eclipse to develop the project? If so, try right click on the project -> Export. Commented Mar 5, 2015 at 17:28
  • Have you configured a SpringBootServletInitializer with your @SpringApplication annotated class to boot up your application? Commented Mar 5, 2015 at 17:41
  • @dunni I have no @SpringApplication class (I did not even find such an annotation in any spring documentation), I have a class with a main(args) function that does SpringApplication app = new SpringApplication(App.class); and app.run(args);. For the maven embedded tomcat, I do have a class extending SpringBootServletInitializer, but did not need to declare it anywhere. I will look into this. Commented Mar 6, 2015 at 9:01

1 Answer 1

1

I managed to build a war following dunni's advice.

Basically, I needed to add a @SpringBootApplication annotation on the class extending SpringBootServletInitializer, and override its configure method.

So the diff of my code is like:

+@SpringBootApplication public class WebAppInitializer extends SpringBootServletInitializer { + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(App.class); + } 

I still have an error but only after spring starts, but I will ask about that in a different question.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.