【问题标题】:Spring boot application stopping without any error on consoleSpring Boot 应用程序在控制台上停止而没有任何错误
【发布时间】:2018-12-19 05:09:11
【问题描述】:

我已经使用 maven 创建了 Spring Boot 应用程序。我为应用程序构建了一个可执行 jar,尝试使用以下命令在 EC2 实例免费层窗口上运行它
java -jar com-spring-boot-apps-0.0.1-SNAPSHOT.jar --server.port=8181 -Xdebug

有些应用程序没有运行,它存在于控制台上的以下日志中。

log4j:WARN No appenders could be found for logger (org.springframework.web.context.support.StandardServletEnvironment).
log4j:WARN Please initialize the log4j system properly.

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.3.RELEASE)

2018-07-11 13:55:50.762  INFO 2784 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-07-11 13:55:50.768  INFO 2784 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.31
2018-07-11 13:55:50.800  INFO 2784 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : Loaded APR based Apache Tomcat Native library [1.2.17] using APR version [1.6.3].
2018-07-11 13:55:50.803  INFO 2784 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
2018-07-11 13:55:50.805  INFO 2784 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
2018-07-11 13:55:52.060  INFO 2784 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : OpenSSL successfully initialized [OpenSSL 1.0.2o  27 Mar 2018]
2018-07-11 13:55:52.402  INFO 2784 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-07-11 13:55:52.532  INFO 2784 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]

例外:-

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'regionProvider': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.aws.core.region.StaticRegionProvider]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: The region 'ap-south-1a' is not a valid region!

【问题讨论】:

  • 由于对 commons-logging 的传递依赖,我遇到了类似的问题。检查您是否有公共登录到您的依赖项广告,而不是不需要它排除它。这样你至少应该看到错误
  • org.springframework.beans.factory.BeanCreationException:创建名为“regionProvider”的bean时出错:通过构造函数实例化bean失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.cloud.aws.core.region.StaticRegionProvider]:构造函数抛出异常;嵌套异常是 java.lang.IllegalArgumentException:区域“ap-south-1a”不是有效区域!
  • 现在我已经无法胜任了,我从来没有玩过 AWS。您最终是否必须排除 coomons-logging 或者您找到了另一种记录方式?

标签: maven spring-boot amazon-ec2 microservices aws-regions


【解决方案1】:

就我而言,pom.xml 文件中缺少日志记录框架。 我使用的是 spring-boot-starter-parent 版本 2.2.5.RELEASE。 为了解决应用程序没有启动的问题,我在pom.xml中添加了以下内容:

<dependency>
        <artifactId>logback-classic</artifactId>
        <groupId>ch.qos.logback</groupId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

【讨论】:

    【解决方案2】:

    commons-logging 与 log4j 冲突。我已经多次遇到这个问题,每次排除公共日志记录都帮助我解决了这个问题。 推荐检查依赖树。

    mvn dependency:tree > module-dependency.txt
    

    然后在你看到的任何地方排除 commons-loggin

                <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache</groupId>
                    <artifactId>commons-io</artifactId>
                </exclusion>
            </exclusions>
    

    【讨论】:

      【解决方案3】:

      从 application.properties 和 pom.xml 属性中删除 cloud.aws.region.static=ap-south-1a 后,它对我有用。

      但同时,如果我从本地计算机项目设置中删除此属性,则会失败并出现以下错误。

      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'amazonS3': Invocation of init method failed; nested exception is java.lang.IllegalStateException: There is no EC2 meta data available, because the application is not running in the EC2 environment. Region detection is only possible if the application is running on a EC2 instance
      

      【讨论】:

      【解决方案4】:

      区域“ap-south-1a”是不正确的区域。在我看来,它应该是“ap-south-1”。您可以检查 .aws 目录中的配置文件以查看是否正确设置了区域。还要检查环境变量 AWS_DEFAULT_REGION 是否设置正确。

      https://docs.aws.amazon.com/general/latest/gr/rande.html

      【讨论】:

        【解决方案5】:
        【解决方案6】:

        如果启用了端点,您可以通过 JMX 或 HTTP 正确关闭应用程序(将 endpoints.shutdown.enabled=true 添加到您的 application.properties 文件中)。

        /shutdown - 让应用程序正常关闭。 (默认不启用)。

        来自Spring boot documentation

        【讨论】:

          猜你喜欢
          • 2015-05-27
          • 2022-10-18
          • 1970-01-01
          • 1970-01-01
          • 2022-07-01
          • 2019-07-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多