2
votes

How can I create (and access) a deployable war based on the Serving Web Content with Spring MVC guide?

It feels like the steps have all succeeded but then when trying to view the page, a 404 error is returned... possibly I am just trying to access the wrong url?

The tutorial works wonderfully when creating and running the jar but when I attempt to access a web page from the war, it is resulting in a 404 error.

Step 1. Create a deployable war file

  • Make Application class extend SpringBootServletInitializer
  • This leads to Packaging executable jar and war files, which involves changing the packaging tag, and marking embedded container dependencies as “provided”
  • Package the war file with: mvn package

Step 2. Deploy!

  • Copy gs-serving-web-content-0.1.0.war into Tomcat's webapps directory
  • Tomcat then creates the directory gs-serving-web-content-0.1.0
  • Tomcat console says: deployWAR INFO: Deployment of web application archive C:\Programs\apache-tomcat-7.0.56\web apps\gs-serving-web-content-0.1.0.war has finished in 2,746 ms

Step 3. View the webpage (This is where it all goes wrong)

Any help would be greatly appreciated!

1

1 Answers

2
votes

http://localhost:8080/gs-serving-web-content-0.1.0/greeting?name=AAA is the URL that should work but it sounds like your Boot application hasn't started. If it had started, you'd see Boot's usual output in Tomcat's console log.

I'd guess it hasn't started because you haven't told your SpringBootServletInitializer subclass about your application's configuration class(es). Have you overridden configure? It should look something like this:

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