Java – the spring boot rest controller returns 404 when deployed on an external Tomcat 9 server
I have a spring boot rest web application that runs perfectly on an embedded server However, in accordance with the blog https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto -After the steps mentioned in create - A - deployable - War - file, I received a 404 error message and sent the resources on the server to me I use Java 1.8.0 locally 0_ 212 and uses Java 1.8 0_ 131 and deployed my application 9 on the server on Tomcat One thing that puzzles me is that I can access the repository that extends crudrepository Here are my entry points for application
@SpringBootApplication
@ComponentScan(basePackages = "com.dbe.ref")
public class RefmsApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(RefmsApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(RefmsApplication.class,args);
}
And my POM xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dbe.ref</groupId>
<artifactId>refms</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>refms</name>
<description>project for Rural electrification fund</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>LATEST</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<start-class>com.RefmsApplication</start-class>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>angularjs</artifactId>
<version>1.4.10</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.4</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>font-awesome</artifactId>
<version>4.7.0</version>
</dependency>
<dependency>
<groupId>eu.michael-simons</groupId>
<artifactId>wro4j-spring-boot-starter</artifactId>
<version>0.3.4</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.14</version>
</dependency>
<dependency>
<groupId>net.sourceforge.dynamicreports</groupId>
<artifactId>dynamicreports-core</artifactId>
<version>5.0.0</version>
</dependency>
</dependencies>
<build>
<finalName>refms</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
This is part of the log:
2017-09-19 10:38:20.564 INFO 6660 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'errorPageFilter' to: [/*] 2017-09-19 10:38:20.565 INFO 6660 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*] 2017-09-19 10:38:20.566 INFO 6660 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 2017-09-19 10:38:20.568 INFO 6660 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*] 2017-09-19 10:38:20.568 INFO 6660 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*] 2017-09-19 10:38:20.571 INFO 6660 --- [ main] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*] 2017-09-19 10:38:20.571 INFO 6660 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'configurableWroFilter' to urls: [/wro4j/*] 2017-09-19 10:38:20.572 INFO 6660 --- [ main] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServletRegistration' to [/refms/*] 2017-09-19 10:38:20.573 INFO 6660 --- [ main] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
Solution
By default, there are some differences when deploying applications on embedded servers and external servers
Using an embedded server, you can access your
http://localhost:<port>/<resourceName>
If you deploy war in another container, you need to add the application name using the following version:
http://localhost:<port>/<applicationNameWithVersion>/<resourceName>
For example, if you deploy this example, the URL of the embedded server is:
http://localhost:8080/greeting
And externally deployed applications, as follows:
http://localhost:8999/gs-rest-service-0.1.0/greeting
Note: this URL belongs to my application server, so some changes may be made to your URL
If you need help, please comment
