Skip to content
Advertisement

Deploy WAR to Tomcat (Spring Boot + Angular)

I am trying to deploy the Spring Boot Application with WAR packaging to Tomcat 10. The application gets deployed successfully, however, when I try to access the endpoints it results in 404 Not Found.

WAR File: application.war

JavaScript

Tomcat webapps/application folder consists of following and index.html (Angular) have <base href="/">

enter image description here


As discussed here, I have added a class AppServletInitializer which extends SpringBootServletInitializer as follow

JavaScript

In pom.xml, I have added the dependency for spring-boot-starter-tomcat, tomcat-embed-jasper and set packaging option as war. I have shared the simplified (removed dependency, plugins. will add the same if required)

pom.xml

JavaScript

Application.java

JavaScript

application.yml

JavaScript

We are using Angular on the client-side and resources are located in the static folder.
Resource Location

Environment: Spring Boot 2.1.8, Angular 8, Java 11,

I have already referred, unfortunately, none of them is working for me. Any help would be Appreciated

  1. Create a Deployable War File
  2. Spring Boot War Deploy
  3. Can not access deployed WAR file on Tomcat

Advertisement

Answer

The configuration was correct in the Project. As mentioned in the comment, there might be some issue with Tomcat 10 as it was in the alpha version. I have used Tomcat 9 it was working fine.

The configuration are as below.

Step 1: Change the packing option to war in pom.xml

<packaging>war</packaging>

Step 2: extends SpringBootServletInitializer

JavaScript

Step 3: Create WAR file

JavaScript

And there we go! We can access the endpoints at

JavaScript

We can also create the profile for war as below

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement