【问题标题】:Spring boot 1.5.2 - web application stops after loading logo?Spring boot 1.5.2 - Web 应用程序在加载徽标后停止?
【发布时间】:2018-02-05 17:48:09
【问题描述】:

我的Spring Boot有个很奇怪的问题,我不知道为什么使用Spring Boot的web应用程序无法启动,即使我直接在终端上运行它也没有输出错误。

java -jar /var/lib/tomcat/webapps/rasdaman.war
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 :: (v1.5.2.RELEASE)

[rasdaman@osboxes rasdaman]$ echo $?
1

这是应用程序类https://pastebin.com/rinWbp9z,这个Web 应用程序使用Liquibase 填充数据库模式和Spring boot version 1.5.2。你能分享一些调试提示吗?

【问题讨论】:

  • 它真的停止了还是只是停止了日志记录... Spring Boot 1.5 及更高版本不再支持 log4j(log4j2 支持)。
  • 您的日志系统未正确初始化,这就是为什么您在徽标之外看不到任何内容的原因。你确定你的应用没有启动吗?尝试删除您对日志记录配置所做的任何自定义。
  • 我可以将 log4j 与属性文件一起使用,并且此 Web 应用程序可以在我的开发系统上运行而不会出现错误(即:它将继续运行,直到它显示有关 Spring Boot 应用程序在之后启动的日志...秒)。但我不明白为什么这个应用程序如果复制到一个新的虚拟机,它会在徽标(?)之后立即停止。我尝试将 log4j 属性文件中的日志级别设置为 DEBUG,但它也没有显示任何内容。我认为 Spring Boot 创建了一个胖 jar,所以所有依赖项都在这个(war/jar)文件中。
  • 您的代码需要在此处,而不是在其他站点上,并且您需要将其减少到可以证明问题minimal reproducible example 的程度。请阅读How to Ask
  • stackoverflow.com/questions/45776035/…,看起来和你的问题一样

标签: java spring spring-boot runtime-error liquibase


【解决方案1】:

所以,问题是,我使用 log4.properties out of war 文件。然后,当我开始这场战争时,它会显示非常好的这样的信息:

java -jar target/petascope_main/rasdaman.war
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 ::        (v1.5.2.RELEASE)

Aug 28, 2017 6:00:31 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
Aug 28, 2017 6:00:32 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.5.11
Aug 28, 2017 6:00:33 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring embedded WebApplicationContext
Aug 28, 2017 6:00:38 PM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Tomcat

然后,我在 src/main/resources 中添加了一个 log4j.properties 文件,内容如下:

log4j.rootLogger=debug, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%t %-5p %c{2} - %m%n

之后,我可以看到 Spring 的详细日志,它使 Tomcat 停止:

***************************
APPLICATION FAILED TO START
***************************

Description:

Field abstractHandler in org.rasdaman.ApplicationMain required a single bean, but 7 were found:
    - KVPRasqlServiceHandler: defined in URL [jar:file:/home/rasdaman/build/applications/petascope/target/petascope_main/rasdaman.war!/WEB-INF/classes!/petascope/controller/handler/service/KVPRasqlServiceHandler.class]
    - KVPWCPSServiceHandler: defined in URL [jar:file:/home/rasdaman/build/applications/petascope/target/petascope_main/rasdaman.war!/WEB-INF/classes!/petascope/controller/handler/service/KVPWCPSServiceHandler.class]
    - SOAPWCSServiceHandler: defined in URL [jar:file:/home/rasdaman/build/applications/petascope/target/petascope_main/rasdaman.war!/WEB-INF/classes!/petascope/controller/handler/service/SOAPWCSServiceHandler.class]
    - KVPWCSTServiceHandler: defined in URL [jar:file:/home/rasdaman/build/applications/petascope/target/petascope_main/rasdaman.war!/WEB-INF/classes!/petascope/controller/handler/service/KVPWCSTServiceHandler.class]
    - XMLWCSServiceHandler: defined in URL [jar:file:/home/rasdaman/build/applications/petascope/target/petascope_main/rasdaman.war!/WEB-INF/classes!/petascope/controller/handler/service/XMLWCSServiceHandler.class]
    - KVPWCSServiceHandler: defined in URL [jar:file:/home/rasdaman/build/applications/petascope/target/petascope_main/rasdaman.war!/WEB-INF/classes!/petascope/controller/handler/service/KVPWCSServiceHandler.class]
    - KVPWMSServiceHandler: defined in URL [jar:file:/home/rasdaman/build/applications/petascope/target/petascope_main/rasdaman.war!/WEB-INF/classes!/petascope/controller/handler/service/KVPWMSServiceHandler.class]


Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

好吧,我必须说,如何隐藏错误真的令人印象深刻。

【讨论】:

  • “好吧,我必须说,如何隐藏错误确实令人印象深刻。” - 写得好..这里也一样。
【解决方案2】:

看来,你的 logback 配置是正确的!

当您配置 logback-spring.xml 之后,日志不会出现在控制台上。 相反,您需要转到您在 logback-spring.xml 文件中配置的 LOG_HOME 位置。

所有日志都将在文件中,而不是在控制台上。

如果这能解决您的问题,请告诉我。

【讨论】:

  • 感谢您尝试解决这个问题,这是很久以前的事了,我不记得了。
猜你喜欢
  • 2017-04-07
  • 1970-01-01
  • 2018-07-15
  • 2019-04-26
  • 1970-01-01
  • 2017-04-14
  • 2021-09-22
  • 1970-01-01
  • 2018-07-03
相关资源
最近更新 更多