简体   繁体   English

Spring 应用程序在启动时关闭

[英]Spring application shut down at startup

I have this strange behaviour with my spring boot application where suddently the startup process doesn't work anymore.我的 spring 启动应用程序有这种奇怪的行为,突然启动过程不再起作用。 Here's the all the log:这是所有日志: 在此处输入图像描述 I really can't say what's wrong since it stopped working.我真的不能说什么是错的,因为它停止工作。 I also fetched on git the remote version of the code that is deployed and working right now.我还在git上获取了已部署并立即运行的代码的远程版本。 I use Intellij Idea as IDE, I have already restarted the IDE and the laptop.我使用Intellij Idea作为 IDE,我已经重新启动了 IDE 和笔记本电脑。 I looked over the Internet but everyone having this issue has problems abot pom or dependency.我查看了互联网,但每个遇到这个问题的人都有关于 pom 或依赖的问题。 I can't get a clue from the logs.我无法从日志中得到线索。 Thanks in advance.提前致谢。

EDIT: Here is my pom.xml编辑:这是我的pom.xml

<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>
    <parent>
        <groupId>it.reag</groupId>
        <artifactId>reag-common-api</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>reag-mailsender-batch</artifactId>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>it.reag</groupId>
            <artifactId>reag-common-api-model</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
        </dependency>
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>6.1.0.jre8</version>
        </dependency>
    </dependencies>


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

</project>

Note that if I change the spring-boot-starter dependency with spring-boot-starter-web the app works, but I don't understand why.请注意,如果我使用spring-boot-starter-web更改spring-boot-starter依赖项,则该应用程序可以工作,但我不明白为什么。 I don't use any of the feature of web environment.我不使用 web 环境的任何功能。 Also, it worked perfectly until the other day with the spring-boot-starter dependency.此外,直到前几天使用spring-boot-starter依赖项,它都可以完美运行。

Leaving this answer as it may help others.留下这个答案,因为它可能会帮助其他人。 If one defines a parent in pom like you have here:如果像您在这里定义的那样在 pom 中定义父级:

<parent>
        <groupId>it.reag</groupId>
        <artifactId>reag-common-api</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

Then a simple dependency of spring-boot-starter-web in this module pom may not be the same as you expected, it may be customized in parent, aka reag-common-api pom, servlet container may be removed there.那么这个模块 pom 中一个简单的 spring-boot-starter-web 依赖可能和你想象的不一样,它可能是在 parent 中自定义的,也就是 reag-common-api pom,servlet 容器可能会在那里被删除。 This happens because of dependency hierachy rule in maven.发生这种情况是因为 maven 中的依赖层次规则。 In this way, in order to verify that a missing container is the reason why spring application starts and quits, one can use mvn dependency:tree to see if a tomcat or undertow or netty is shown as a container (not an exact expression).这样,为了验证缺少容器是 spring 应用程序启动和退出的原因,可以使用mvn dependency:tree查看 tomcat 或 undertow 或 netty 是否显示为容器(不是精确表达式)。

In my project, this would be neede for submodule pom:在我的项目中,子模块 pom 需要这样做:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-undertow</artifactId>
        </dependency>

As its parent has this:因为它的父母有这个:

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <version>${spring-boot.version}</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-tomcat</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM