Error starting Spring Boot with Tomcat 9.0.21

Asked

Viewed 199 times

1

Situation: I have an application implemented with Spring Boot and need to deploy to Tomcat (V9.0.21).

Problem: I managed the package . War normally and made the deploy. I start the application normally, but soon after the application is restarted, as the first time the start was successful, the second time gives errors of already used ports and the application is dropped.

Artifacts:

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.1.7.RELEASE</version>
    </parent>
    <groupId>br.com.mensagem</groupId>
    <artifactId>mensagem</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>api-mensagem</name>
    <description>Websocket server de mensagens</description>
    <packaging>war</packaging>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</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-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.corundumstudio.socketio</groupId>
            <artifactId>netty-socketio</artifactId>
            <version>1.7.12</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>javax.el-api</artifactId>
            <version>3.0.0</version>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

Springbootapplication.java

package br.com.mensagemwebsocket;

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 MensagemApplication extends SpringBootServletInitializer {

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

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(MensagemApplication.class);
    }
}

application properties

spring.thymeleaf.cache=false
#server.port=8088

#server.address=192.168.0.45
# ===============================
# = DATA SOURCE
# ===============================

## DEV
# Connection url for the database "dbacacio"
spring.datasource.url = jdbc:mysql://localhost:3306/dbacacio

# Username and password
spring.datasource.username = root

# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1

# ===============================
# = JPA / HIBERNATE
# ===============================

# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
# stripped before adding them to the entity manager).

# Show or not log for each sql query
spring.jpa.show-sql = true

# Hibernate ddl auto (create, create-drop, update): with "update" the database
# schema will be automatically updated accordingly to java entities found in
# the project
#spring.jpa.hibernate.ddl-auto = update

# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy

# Allows Hibernate to generate SQL optimized for a particular DBMS
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
  • Detail, I don’t use spring-boot-devtools

  • 1

    how did you do it: "I generated the package . War normally and deploy."? which commands executed?

  • 1

    "soon after the application is restarted,"why? you restarted? it restarts itself? but this has been implemented by you or she does it alone for no reason?

  • @Danilo I built (.War) using Maven (clean install)

  • 1

    Just so I understand it better, are you putting the . War generated inside the Tomcat? If so, is all this local? You have changed the port of Tomcat or your application in . properties?

  • It restarts on its own, actually this is a problem.... starts once good and all of a sudden it restarts. This restart starts giving port errors.

  • @Caioaugustopapai I send the . War by the "Tomcat Web Application Manager" in "WAR file to deploy". Yes, all this is in my location. When the Tomcat port is in the 8080 and in my application I have not configured any port.

  • I’ll put my properties here.

  • 2

    Why does it remain alone? I suggest checking your catalina.out to identify problems. Anyway, if the port is already being used, it means that the process may have stopped working (Restart reason) and not.

  • As below I found the solution! Valeus!!!

Show 5 more comments

1 answer

1

I found the solution... wow, good, after analyzing codes, to inspire in your comments I found the problem.

Had a class Serveletinitializer extending Springbootservletinitializer.

There was the problem. I removed this class and everything went beautiful as it should be. Strange is that the Eclipse did not give this error, but okay.

I had the intuition to remove this class, I do not know why I put, when I saw this part of the log presented in the console.

Thank you all for your suggestions!!!



  [1]: https://i.stack.imgur.com/yTJct.jpg

Browser other questions tagged

You are not signed in. Login or sign up in order to post.