0

Não consigo fazer o deploy de um projeto spring boot em um tomcat9 externo. Eu fiz uma API rest e estou tentando fazer o deploy no tomcat mas mesmo se eu tentar fazer isso pelo manager que está funcionando bem por sinal) ou se eu copiar o .war para a pasta webapps, não consigo ver o spring iniciando no log do console do catalina.bat. Estou tentando acessar localhost:8080/scim (que é o nome do meu .war - scim.war), mas recebo o erro 404. Eu estava esperando ver o erro de página em branco do Spring, mas ele não aparece. Quando comparo com este projeto (cujo .war tem o nome de web-services.war) que encontrei neste tutorial do JavaTPoint não vejo diferença no POM.xml, ou na classe principal. Eu compilei o .war basicamente com o comando mvn clean install, e ele não traz nenhum erro, então acho que está certo. Alguém pode me ajudar? Todos os outros links no stackoverflow não funcionam para mim, realmente procurei bastante. Qualquer outro detalhe, é só me dizer.

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

Como podem ver, a aplicação web-services iniciou corretamente, e comparando os arquivos, não consegui encontrar diferenças que possam causar a não inicialização do meu spring no tomcat.

1 Resposta 1

0

Meu TomCat estava configurado para utilizar a JRE com Java 8 enquanto meu projeto estava configurado para utilizar Java 11.

Alterei o JRE_HOME para o mesmo caminho do JAVA_HOME que está com a JDK 11, e o Spring iniciou ao realizar o deploy no TomCat.

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

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

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .