3

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!

user3746480
  • 333
  • 5
  • 17
  • 2
    Why are you using Tomcat 10? It's still only an *alpha* release (10.0.0-M10 (**alpha**)), not even in beta yet. Worse, it is **not backwards compatible**, so it cannot run Spring code targeted for Tomcat 9. See [duplicate link](https://stackoverflow.com/a/63926949/5221149). – Andreas Dec 03 '20 at 00:26
  • And finally... just _don't_. Deploying into a container is a maintenance headache that the Boot team put in a lot of effort to make unnecessary for you. – chrylis -cautiouslyoptimistic- Dec 03 '20 at 02:45
  • Thank you Andreas, after setting up everything with tomcat 9 it works as it should. I didn't even know that tomcat 10 is in alpha. It was downloaded automatically as last version through apt-get – user3746480 Dec 03 '20 at 19:43
  • I spent whole day trying everything and that was the cause all along, what a joy. – Trynkiewicz Mariusz Apr 03 '21 at 19:24

0 Answers0