I'm pulling my hairs out because i just can't deploy a spring boot application to an external tomcat9. I did an rest API and i'm trying to deploy on tomcat but even if i try to do it trough the manager (which is working fine by the way) or if i copy the .war to the webapps folder, i can't see the Spring Letters on the console log of catalina.bat. I'm trying to reach at localhost:8080/scim (which is the name of my .war - scim.war) but i get the 404 error. I was expecting to see the white blank page error of Spring, but it don't appear. When i compare to this project that i found on this tutorial from JavaTPoint i cant see any difference on POM.xml, or main class. I packed the .war basically with the mvn clean install
command, and it don't bring any error, so i guess that is right. Can someone help me? All the other links in stackoverflow don't work for me.
Any other details, just tell me.
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>
<groupId>com.ushin</groupId>
<artifactId>scim</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>scim</name>
<description>scim</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.1</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>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>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>scim</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Application.properties
spring.datasource.url=jdbc:mysql://localhost:3306/homologate?allowPublicKeyRetrieval=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=1234
server.servlet.context-path=/scim
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.hibernate.ddl-auto=update
spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER
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 {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){
return builder.sources(ScimApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(ScimApplication.class, args);
}
}
Catalina Log
PS C:\apache-tomcat-9.0.64\bin> .\catalina.bat run
Using CATALINA_BASE: "\apache-tomcat-9.0.64"
Using CATALINA_HOME: "\apache-tomcat-9.0.64"
Using CATALINA_TMPDIR: "\apache-tomcat-9.0.64\temp"
Using JRE_HOME: "C:\Program Files\Java\jre1.8.0_333"
Using CLASSPATH: "\apache-tomcat-9.0.64\bin\bootstrap.jar;\apache-tomcat-9.0.64\bin\tomcat-juli.jar"
Using CATALINA_OPTS: ""
08-Jul-2022 05:11:05.684 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name: Apache Tomcat/9.0.64
08-Jul-2022 05:11:05.689 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Jun 2 2022 19:08:46 UTC
08-Jul-2022 05:11:05.689 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 9.0.64.0
08-Jul-2022 05:11:05.689 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Windows 10
08-Jul-2022 05:11:05.689 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 10.0
08-Jul-2022 05:11:05.689 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
08-Jul-2022 05:11:05.689 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: C:\Program Files\Java\jre1.8.0_333
08-Jul-2022 05:11:05.694 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_333-b02
08-Jul-2022 05:11:05.694 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
08-Jul-2022 05:11:05.694 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:\apache-tomcat-9.0.64
08-Jul-2022 05:11:05.694 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: C:\apache-tomcat-9.0.64
08-Jul-2022 05:11:05.694 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=\apache-tomcat-9.0.64\conf\logging.properties
08-Jul-2022 05:11:05.694 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
08-Jul-2022 05:11:05.694 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
08-Jul-2022 05:11:05.694 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
08-Jul-2022 05:11:05.694 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
08-Jul-2022 05:11:05.694 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=\apache-tomcat-9.0.64
08-Jul-2022 05:11:05.694 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=\apache-tomcat-9.0.64
08-Jul-2022 05:11:05.694 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=\apache-tomcat-9.0.64\temp
08-Jul-2022 05:11:05.701 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded Apache Tomcat Native library [1.2.33] using APR version [1.7.0].
08-Jul-2022 05:11:05.701 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true], UDS [true].
08-Jul-2022 05:11:05.701 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
08-Jul-2022 05:11:05.720 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1o 3 May 2022]
08-Jul-2022 05:11:06.158 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
08-Jul-2022 05:11:06.222 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [770] milliseconds
08-Jul-2022 05:11:06.270 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
08-Jul-2022 05:11:06.270 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.64]
08-Jul-2022 05:11:06.285 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [C:\apache-tomcat-9.0.64\webapps\scim.war]
08-Jul-2022 05:11:12.779 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.
08-Jul-2022 05:11:13.583 WARNING [main] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [505] milliseconds.
08-Jul-2022 05:11:13.618 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 [7,333] ms
08-Jul-2022 05:11:13.629 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [C:\apache-tomcat-9.0.64\webapps\web-services.war]
08-Jul-2022 05:11:17.351 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.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.2.RELEASE)
2022-07-08 05:11:19.864 INFO 28736 --- [ main] pringBootWarDeploymentExampleApplication : Starting SpringBootWarDeploymentExampleApplication v0.0.1-SNAPSHOT on SAO6-L02008 with PID 28736 (C:\apache-tomcat-9.0.64\webapps\web-services\WEB-INF\classes started by gbrasolin in C:\apache-tomcat-9.0.64\bin)
2022-07-08 05:11:19.880 INFO 28736 --- [ main] pringBootWarDeploymentExampleApplication : No active profile set, falling back to default profiles: default
2022-07-08 05:11:22.605 INFO 28736 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2613 ms
2022-07-08 05:11:23.616 INFO 28736 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2022-07-08 05:11:24.128 INFO 28736 --- [ main] pringBootWarDeploymentExampleApplication : Started SpringBootWarDeploymentExampleApplication in 6.062 seconds (JVM running for 19.031)
08-Jul-2022 05:11:24.177 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [C:\apache-tomcat-9.0.64\webapps\web-services.war] has finished in [10,548] ms
08-Jul-2022 05:11:24.177 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-9.0.64\webapps\docs]
08-Jul-2022 05:11:24.237 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-9.0.64\webapps\docs] has finished in [60] ms
08-Jul-2022 05:11:24.237 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-9.0.64\webapps\examples]
08-Jul-2022 05:11:25.096 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-9.0.64\webapps\examples] has finished in [859] ms
08-Jul-2022 05:11:25.096 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-9.0.64\webapps\host-manager]
08-Jul-2022 05:11:25.187 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 [91] ms
08-Jul-2022 05:11:25.187 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-9.0.64\webapps\manager]
08-Jul-2022 05:11:25.298 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-9.0.64\webapps\manager] has finished in [111] ms
08-Jul-2022 05:11:25.298 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\apache-tomcat-9.0.64\webapps\ROOT]
08-Jul-2022 05:11:25.349 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\apache-tomcat-9.0.64\webapps\ROOT] has finished in [51] ms
08-Jul-2022 05:11:25.365 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
08-Jul-2022 05:11:25.399 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [19180] milliseconds
As you can see, it seems that spring only starts on the project that i'm using to compare with.
CodePudding user response:
You are running Tomcat on Java 8:
Using JRE_HOME: "C:\Program Files\Java\jre1.8.0_333"
Your application is configured to use Java 11:
<java.version>11</java.version>
Running on Java 8, Tomcat will be unable to read the classes from your application that's using Java 11. It's unfortunate that Tomcat doesn't log anything about this which makes the problem hard to diagnose.
You should be able to fix the problem by running Tomcat on Java 11 or by changing your application to use Java 8.