Spring Boot嵌入式Tomcat在特定时间后关闭

时间:2018-09-25 16:21:11

标签: spring-boot tomcat

我真的不明白我的嵌入式Tomcat配置出了什么问题。它可以正常工作,但是当我尝试使其远程保持活动状态时,大约一小时后它将关闭。我们使用Ubuntu服务器。

要启动它,我使用以下nohup命令来确保它将在后台运行:

~:$ nohup java -jar MyApp.jar &

这是我的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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>br.com.infrati</groupId>
    <artifactId>pesquisa-sms-java</artifactId>
    <version>0.0.1</version>
    <packaging>jar</packaging>

    <name>pesquisa-sms-java</name>
    <description>Backend de Pesquisa SMS</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</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>1.8</java.version>
        <start-class>br.com.infrati.dev.pesquisasms.PesquisaSmsApplication</start-class>
    </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>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.7.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.7.0</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>5.0.9.RELEASE</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.9.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-gcp-pubsub</artifactId>
            <version>1.0.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-core</artifactId>
            <version>5.0.8.RELEASE</version>
        </dependency>



        <!-- Test Dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <version>3.10.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>2.21.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-core</artifactId>
            <version>1.3</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-library</artifactId>
            <version>1.3</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.skyscreamer</groupId>
            <artifactId>jsonassert</artifactId>
            <version>1.5.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>5.0.8.RELEASE</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.modelmapper</groupId>
            <artifactId>modelmapper</artifactId>
            <version>2.1.0</version>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>test</scope>
            <version>1.4.194</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <executable>true</executable>
                    <profiles>prod</profiles>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

以下是意外关闭之前的应用程序日志:

2:org.apache.tomcat.util.net.SecureNioChannel@585cf079:java.nio.channels.SocketChannel[connected local=/172.31.38.42:8443 remote=/189.6.240.68:4548]], Status in: [OPEN_READ], State out: [OPEN]
2018-09-25 02:51:09,741 DEBUG org.apache.juli.logging.DirectJDKLog [https-jsse-nio-8443-exec-8] Pushed Processor [org.apache.coyote.http11.Http11Processor@19521c97]
2018-09-25 02:52:09,801 DEBUG org.apache.juli.logging.DirectJDKLog [https-jsse-nio-8443-exec-7] Processing socket [org.apache.tomcat.util.net.SecureNioChannel@585cf079:java.nio.channels.SocketChannel[connected local=/172.31.38.42:8443 remote=/189.6.240.68:4548]] with status [ERROR]
2018-09-25 02:52:09,802 DEBUG org.apache.juli.logging.DirectJDKLog [https-jsse-nio-8443-exec-7] Found processor [null] for socket [org.apache.tomcat.util.net.SecureNioChannel@585cf079:java.nio.channels.SocketChannel[connected local=/172.31.38.42:8443 remote=/189.6.240.68:4548]]
2018-09-25 02:52:09,803 DEBUG org.apache.juli.logging.DirectJDKLog [https-jsse-nio-8443-exec-7] Counting down[https-jsse-nio-8443-exec-7] latch=1
2018-09-25 02:52:09,803 DEBUG org.apache.juli.logging.DirectJDKLog [https-jsse-nio-8443-exec-7] Socket: [org.apache.tomcat.util.net.SecureNioChannel@585cf079:java.nio.channels.SocketChannel[closed]] closed
2018-09-25 02:53:29,427 DEBUG org.apache.juli.logging.DirectJDKLog [ContainerBackgroundProcessor[StandardEngine[Tomcat]]] Start expire sessions StandardManager at 1537844009427 sessioncount 2
2018-09-25 02:53:29,428 DEBUG org.apache.juli.logging.DirectJDKLog [ContainerBackgroundProcessor[StandardEngine[Tomcat]]] End expire sessions StandardManager processingTime 1 expired sessions: 0
2018-09-25 02:54:03,168 INFO org.springframework.context.support.AbstractApplicationContext [Thread-3] Closing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@131ef10: startup date [Tue Sep 25 02:29:24 UTC 2018]; root of context hierarchy
2018-09-25 02:54:03,178 INFO org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup [Thread-3] Stopping beans in phase 2147483647
2018-09-25 02:54:03,179 INFO org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup [Thread-3] Stopping beans in phase 0
2018-09-25 02:54:03,179 INFO org.springframework.integration.endpoint.EventDrivenConsumer [Thread-3] Removing {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2018-09-25 02:54:03,180 INFO org.springframework.integration.channel.AbstractSubscribableChannel [Thread-3] Channel 'application.errorChannel' has 0 subscriber(s).
2018-09-25 02:54:03,180 INFO org.springframework.integration.endpoint.AbstractEndpoint [Thread-3] stopped _org.springframework.integration.errorLogger
2018-09-25 02:54:03,184 INFO org.springframework.scheduling.concurrent.ExecutorConfigurationSupport [Thread-3] Shutting down ExecutorService 'taskScheduler'
2018-09-25 02:54:03,188 INFO org.springframework.jmx.export.MBeanExporter [Thread-3] Unregistering JMX-exposed beans on shutdown
2018-09-25 02:54:03,188 INFO org.springframework.jmx.support.MBeanRegistrationSupport [Thread-3] Unregistering JMX-exposed beans
2018-09-25 02:54:03,197 INFO org.springframework.orm.jpa.AbstractEntityManagerFactoryBean [Thread-3] Closing JPA EntityManagerFactory for persistence unit 'default'
2018-09-25 02:54:03,198 INFO com.zaxxer.hikari.HikariDataSource [Thread-3] HikariPool-1 - Shutdown initiated...
2018-09-25 02:54:03,230 INFO com.zaxxer.hikari.HikariDataSource [Thread-3] HikariPool-1 - Shutdown completed.

我应该做一些其他配置来保持此Tomcat存活吗?也许是SO调整?但是我真正不明白的是,如何在没有任何命令或外部事件(重新启动,关闭电源)的情况下关闭此应用程序?

有人可以帮我吗?

谢谢

安德烈

0 个答案:

没有答案