Spring Boot application runs normally on embedded Tomcat server when I run it from Eclipse, but when I deploy it to external tomcat server (on Linode VPS running Ubuntu) I'm getting HTTP 404 status.
It's currently only backend part of app (if it matters at all), so I don-t have any index.html or anything like that in root folder of app. But in postman, or through links I'm getting responses normally when run locally.
I've tried everything that people recommend and still don't know where the problem is.
- There are no exceptions in tomcat when app is being deployed
- Tomcat manager works normally and shows that the application is up and running
- I'm building this app with Maven with clean install with java version 11. Tomcat is version 10.
- I've done everything from this link When Spring Boot app is deployed on tomcat gives 404 error
On embeded tomcat I can get Json with this url: http://localhost:8888/gallery/autori
On remote tomcat manager works like it should:
http://xx.xx.xxx.xxx:8080/manager/html/
but my application is not working. I've tried different urls
http://xx.xx.xxx.xxx:8080/gallery
http://xx.xx.xxx.xxx:8080/gallery/autori
http://xx.xx.xxx.xxx:8080/gallery/gallery/autori
I've tried those different urls because in application.properties I have server.port and context-path defined (even though it doesn't matter on remote server, it-s only for embeded tomcat, as far as I know). Also I tried without those two defined ofcourse...
server.port=8888
server.servlet.context-path=/gallery
Here is 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<artifactId>gallery</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>gallery</name>
<description>My App</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
</properties>
<dependencies>
<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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sipios</groupId>
<artifactId>spring-search</artifactId>
<version>0.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.5</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<!--dependencies for deployment-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>gallery</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source> <!-- maven.compiler.source -->
<target>11</target> <!-- maven.compiler.target -->
</configuration>
</plugin>
</plugins>
</build>
</project>
Here is my starter application:
@SpringBootApplication
public class GalleryApplication extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(GalleryApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(GalleryApplication.class);
}
}
/etc/systemd/system/tomcat.service
Environment=JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64
java version on remote server:
java -version
openjdk version "11.0.9.1" 2020-11-04
OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04)
OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)
tomcat version
Server version: Apache Tomcat/10.0.0-M10
Server built: Nov 12 2020 11:01:14 UTC
Server number: 10.0.0.0
OS Name: Linux
OS Version: 5.4.0-48-generic
Architecture: amd64
JVM Version: 11.0.9.1+1-Ubuntu-0ubuntu1.20.04
JVM Vendor: Ubuntu
I now see that tomcat uses OpenJDK 11 and not OracleJDK 11. COuld that be the source of problem? Please help!