Home > Enterprise >  Spring Application gets 404 error on TomCat
Spring Application gets 404 error on TomCat

Time:07-14

how are u?

I'm doing a Spring Boot Application and i'm getting the 404 error on TomCat. I'm using Maven to build the .WAR file and do the deploy to TomCat with the tomcat7-maven-plugin. I already read a lot of topics with a context very similar to mine but i cant find a solution. Something that i notice, is that when i do the deploy, the Spring Letters not show anymore on TomCat prompt.

HTTP Status 404 – Not Found
Type Status Report

Message The requested resource [/scim/] is not available

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

Apache Tomcat/9.0.64

Print of the error

Some dudes try to resolve this putting extends SpringBootServletInitializer and the

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){
    return builder.sources(ScimApplication.class);
}

on the main class, but i already did that, and didn't worked.

I used to compile the .war file with the mvn clean install command, then i do the mvn clean tomcat7:deploy to do the deploy directly to the TomCat, that i already configurated the user on tomcat-users.xml, and add the server tag on the settings.xml on conf folder of Maven.

Even if i enter on the TomCat's manager page, and do the deploy from there, when i try localhost:8080/scim, i get 404 error.

I will put my initialization TomCat log here, as well my Controller, POM.xml and Main class.

Thank you and if you guys need more information, just tell me.

TomCat Log Initialization

07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name:   Apache Tomcat/9.0.64
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Jun 2 2022 19:08:46 UTC
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 9.0.64.0
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Windows 10
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            10.0
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             C:\Program Files\Java\jre1.8.0_333
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_333-b02
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         C:\apache-tomcat-9.0.64
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         C:\apache-tomcat-9.0.64
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=\apache-tomcat-9.0.64\conf\logging.properties
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=\apache-tomcat-9.0.64
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=\apache-tomcat-9.0.64
07-Jul-2022 11:09:14.795 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=\apache-tomcat-9.0.64\temp
07-Jul-2022 11:09:14.811 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded Apache Tomcat Native library [1.2.33] using APR version [1.7.0].
07-Jul-2022 11:09:14.811 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true], UDS [true].
07-Jul-2022 11:09:14.827 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
07-Jul-2022 11:09:14.827 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1o  3 May 2022]
07-Jul-2022 11:09:15.215 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
07-Jul-2022 11:09:15.265 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [710] milliseconds
07-Jul-2022 11:09:15.297 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
07-Jul-2022 11:09:15.297 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.64]
07-Jul-2022 11:09:15.328 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [C:\apache-tomcat-9.0.64\webapps\scim.war]
07-Jul-2022 11:09:19.655 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
07-Jul-2022 11:09:20.057 WARNING [main] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [269] milliseconds.
07-Jul-2022 11:09:20.075 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [C:\apache-tomcat-9.0.64\webapps\scim.war] has finished in [4,747] ms
07-Jul-2022 11:09:20.075 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-9.0.64\webapps\docs]
07-Jul-2022 11:09:20.127 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-9.0.64\webapps\docs] has finished in [52] ms
07-Jul-2022 11:09:20.127 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-9.0.64\webapps\examples]
07-Jul-2022 11:09:20.684 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-9.0.64\webapps\examples] has finished in [557] ms
07-Jul-2022 11:09:20.684 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-9.0.64\webapps\host-manager]
07-Jul-2022 11:09:20.757 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-9.0.64\webapps\host-manager] has finished in [72] ms
07-Jul-2022 11:09:20.757 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-9.0.64\webapps\manager]
07-Jul-2022 11:09:20.794 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-9.0.64\webapps\manager] has finished in [37] ms
07-Jul-2022 11:09:20.794 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-9.0.64\webapps\ROOT]
07-Jul-2022 11:09:20.849 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-9.0.64\webapps\ROOT] has finished in [55] ms
07-Jul-2022 11:09:20.849 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
07-Jul-2022 11:09:20.866 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [5601] milliseconds

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.7.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.ushin</groupId>
    <artifactId>scim</artifactId>
    <name>scim</name>
    <description>scim</description>
    <packaging>war</packaging>
    <properties>
        <java.version>11</java.version>
    </properties>
    <dependencies>
        <!--Spring-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</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-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <!--MySQL-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.24</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity</artifactId>
            <version>1.5</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>scim</finalName>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                        <fork>true</fork>
                        <executable>C:\Users\gbrasolin\.jdks\corretto-11.0.15\bin\javac.exe</executable>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.2</version>
                    <configuration>
                        <url>http://localhost:8080/manager/text</url>
                        <server>scim</server>
                        <path>/scim</path>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

Controller

package com.ushin.scim.controllers;

import com.ushin.scim.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@Controller
@RequestMapping(value = "/Users")
public class UserController {

    UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    @RequestMapping(method = RequestMethod.POST)
    public @ResponseBody Map createUser(@RequestBody Map<String, Object> payload, HttpServletResponse response){
        return userService.createUser(payload, response);
    }

    @RequestMapping(method = RequestMethod.GET)
    public @ResponseBody Map getUsers(@RequestParam Map<String, String> payload) throws IOException {
        return userService.getUsers(payload);
    }

    @RequestMapping(value = "/{id}")
    public @ResponseBody Map getSingleUser (@PathVariable String id,  HttpServletResponse response){
        return userService.getSingleUser(id, response);
    }

    @RequestMapping(method = RequestMethod.PUT, value = "/{id}")
    public @ResponseBody Map updateUser(@RequestBody Map<String, Object> payload, @PathVariable String id){
        return userService.updateUser(payload, id);
    }

    @RequestMapping(method = RequestMethod.PATCH, value = "/{id}")
    public @ResponseBody Map disableUser (@RequestBody Map<String, Object> payload, @PathVariable String id){
        return userService.disableUser(payload, id);
    }

}

Main Class

package com.ushin.scim;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

@SpringBootApplication
public class ScimApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(ScimApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){
        return builder.sources(ScimApplication.class);
    }

}

CodePudding user response:

I changed the JRE_HOME (was running java 8) to the same path of JAVA_HOME which is with Java 11, and it worked. Tomcat was on Java 8 and my project was running Java 11.

Log: Using JRE_HOME: "C:\Program Files\Java\jre1.8.0_333"

My POM.xml: <java.version>11</java.version>

  • Related