首页 > 解决方案 > Spring Boot 应用程序在 unix 环境中被关闭

问题描述

我正在尝试在 Unix 环境中运行 Spring Boot 应用程序(.jar)。它会在一段时间内关闭。该应用程序具有 REST Web 服务和调度程序组件。相同的 jar 在 IDE 和 Windows CMD 中运行良好。

2021-01-13 16:46:16.591  INFO 6346 --- [extShutdownHook] o.s.i.endpoint.EventDrivenConsumer       : Removing {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2021-01-13 16:46:16.592  INFO 6346 --- [extShutdownHook] o.s.i.channel.PublishSubscribeChannel    : Channel 'SFTP service.errorChannel' has 0 subscriber(s).
2021-01-13 16:46:16.592  INFO 6346 --- [extShutdownHook] o.s.i.endpoint.EventDrivenConsumer       : stopped bean '_org.springframework.integration.errorLogger'
2021-01-13 16:46:16.598  INFO 6346 --- [extShutdownHook] o.s.s.c.ThreadPoolTaskScheduler          : Shutting down ExecutorService 'taskScheduler'
2021-01-13 16:46:16.601  INFO 6346 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'

调度程序代码片段。我也面临没有调度程序代码的报告问题。

@Component
Public class Task{

@Autowired
Private Environment env;
@Autowired
Private ConnectionFactory conn;

@Scheduled(fixedRate=1500)
public void scheduledRun(){
//monitors map 
}}

添加记录器配置

<configuration scan="true" scanPeriod="30 seconds">
<jmxConfigurator/>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/file-appender.xml"/>

<appender name="SERVICE_DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>logs/service-debug.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <!-- rollover daily -->
        <fileNamePattern>logs/service-debug-%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
        <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
            <!-- or whenever the file size reaches 50MB -->
            <maxFileSize>100MB</maxFileSize>
        </timeBasedFileNamingAndTriggeringPolicy>
    </rollingPolicy>
    <encoder>
        <pattern>%d{dd.MM.yyyy HH:mm:ss.SSS z} [%thread] %X{instructionsId}-%X{fileName} %X{step} %-5level %logger{36} - %msg%n</pattern>
    </encoder>
</appender>

<appender name="SERVICE_ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>logs/service-err.log</file>
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
        <level>WARN</level>
    </filter>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <!-- rollover daily -->
        <fileNamePattern>logs/service-err-%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
        <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
            <!-- or whenever the file size reaches 50MB -->
            <maxFileSize>100MB</maxFileSize>
        </timeBasedFileNamingAndTriggeringPolicy>
    </rollingPolicy>
    <encoder>
        <pattern>%d{dd.MM.yyyy HH:mm:ss.SSS z} [%thread] %X{instructionsId}-%X{fileName} %X{step} %-5level %logger{36} - %msg%n</pattern>
    </encoder>
</appender>

<logger name="trace" level="TRACE"/>
<springProfile name="prod, uat1">
    <logger name="com.service" level="INFO"/>
</springProfile>
<springProfile name="!prod, !uat1">
    <logger name="com.service" level="DEBUG"/>
    <logger name="org.hibernate.SQL" level="DEBUG" additivity="false">
        <appender-ref ref="SERVICE_DEBUG" />
    </logger>
</springProfile>
<logger name="org.springframework" level="INFO"/>
<logger name="org.hibernate" level="INFO"/>

<root level="INFO">
    <appender-ref ref="SERVICE_DEBUG" />
    <appender-ref ref="SERVICE_ERROR" />
    <appender-ref ref="FILE"/>
</root>

POM 文件

<modelVersion>4.0.0</modelVersion>
<groupId>com.servicep</groupId>
<artifactId>sftpservice</artifactId>
<version>1.0.2-SNAPSHOT</version>

<name>sftp-service</name>
<description>SFTP service</description>

<!-- Properties -->
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <!--<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>-->
    <java.version>1.8</java.version>
    <maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
</properties>

<!-- Spring Boot Parent to control the version of child dependency-->
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <!--<version>2.0.9.RELEASE</version>-->
    <version>2.2.0.RELEASE</version>
</parent>

<!-- Dependencies to build this service - will be imported in project -->
<dependencies>
    <!-- Spring web brings all required dependencies to build web application. i.e. REST Service -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

    <!--Dependency for sftp connection-->
    <dependency>
        <groupId>org.springframework.integration</groupId>
        <artifactId>spring-integration-sftp</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>

    <!--java library to support the SSH protocols on both the client and server side-->
    <dependency>
        <groupId>org.apache.sshd</groupId>
        <artifactId>sshd-core</artifactId>
        <version>1.4.0</version>
        <scope>test</scope>
    </dependency>
    <!--Unit test dependency-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <!--API is used to convert JSON to and from POJO (Plain Old Java Object) using property accessor or using annotations-->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <!--<version>2.9.8</version>-->
        <version>2.10.0</version>
    </dependency>
    <!--logging-->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.25</version>
    </dependency>

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.9</version>
    </dependency>

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpmime</artifactId>
        <version>4.5.9</version>
    </dependency>
</dependencies>

<build>
    <defaultGoal>spring-boot:run</defaultGoal>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <addResources>true</addResources>

            </configuration>
        </plugin> 

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
        </plugin>
    </plugins>
</build>

标签: javaspringspring-bootunixsolaris

解决方案


推荐阅读