java Spring Boot jar 在 CentOS 上崩溃

标签 java spring maven

我有一个非常简单的 SpringBoot 应用程序,它实现了一个简单的 Rest API。

这就是我开始的方式:

package API;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Main {

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

Controller 与此 Controller 放置在同一包中(API 包)。

这是我的 Maven 文件:

<?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>HadoopDriver</groupId>
    <artifactId>HadoopDriver</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.2.RELEASE</version>
    </parent>

    <properties>
        <tomcat.version>8.0.30</tomcat.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.0.2.RELEASE</version>
                <configuration>
                    <executable>true</executable>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-framework-bom</artifactId>
            <version>5.0.6.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>

        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-sns</artifactId>
            <version>1.11.338</version>
        </dependency>

        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-yarn-client</artifactId>
            <version>3.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.0.6.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>2.0.2.RELEASE</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <version>2.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.2</version>
        </dependency>


        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-common</artifactId>
            <version>2.6.1</version>
            <scope>compile</scope>
            <exclusions>
                <exclusion>
                    <groupId>javax.servlet</groupId>
                    <artifactId>servlet-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-hdfs</artifactId>
            <version>2.6.1</version>
            <scope>compile</scope>
            <exclusions>
                <exclusion>
                    <groupId>javax.servlet</groupId>
                    <artifactId>servlet-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>repository.spring.release</id>
            <name>Spring GA Repository</name>
            <url>https://repo.spring.io/plugins-release/</url>
        </pluginRepository>
    </pluginRepositories>
</project>

我在 macOS 上的 IntelliJ Idea 中开发了这个应用程序,并生成了一个 JAR,并将其放置在 Cent OS (EC2) 计算机上,我想从那里运行它。

我生成这样的 list 文件:文件 -> 项目结构 -> Artifact -> + -> JAR -> 从具有依赖项的模块 -> 选择主类 -> 更改 META-INF 的目录到/resources 而不是/java -> 应用 -> 确定

我继续构建 -> 构建 Artifact -> 构建,然后我得到了放置在 /out/artifacts/project_jar 文件夹中的 JAR。

我将此 jar 上传到 Cent OS 机器,当我尝试运行它时,我得到以下输出:

user@host>
log4j:WARN No appenders could be found for logger (org.springframework.web.context.support.StandardServletEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::
user@host>

我没有收到任何错误消息,什么也没有。我不知道在哪里寻找错误,我不知道如何解决这个问题。

请至少告诉我在哪里查看,我如何诊断这个问题,因为我尝试了很多时间但没有结果。

最佳答案

出于以下几个原因,您不想在应用程序中使用 Log4J:

  • 这是 at end of life
  • Spring Boot 已经附带了 Logback 和其他配置日志记录的方法

就您而言,您的日志中可能没有获得足够的详细信息。通过将其添加到您的 application.properties 文件中来提高详细程度:

logging.level.org.springframework=debug

这将允许您在 stdout 中查看 org.springframework 下所有内容的调试日志。

关于java Spring Boot jar 在 CentOS 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50647277/

相关文章:

java - 从命令行搜索 Maven 过滤器

Java Swing : Custom Cell Editor does not return most recent value

java - Springboot/Thymeleaf 在每个页面上从模型中检查当前用户

spring - 正确的 mvc :interceptor configuration in Spring

Spring Web应用程序架构

java - 无法加载来自其他 Maven 模块的应用程序上下文

java - 如何重置 do while 循环?我不断收到 "java.lang.IllegalArgumentException"错误

java - 使用多个 View 填充 JList

java - InjectMocks 对象上的 org.mockito.exceptions.misusing.NotAMockException

Maven "import"范围