问题描述:springboot启动异常,启动后没有日志打印。

问题原因:slf4j日志实现重复,找不到对应实现类。

问题应对:

1. 是不是项目没起来---->打印的日志数据,到这里就不打印了,在run方法后面加了一行输入print,当启动之后使用debug,能运行到此行,说明正常启动成功的。

2.是不是日志框架冲突导致的--->把日志相关的pom以来都注释,发现print的能打印出来,log.info 相关的打印不出来。

把绑定的两块实现类都找了一下:

[jar:file:/D:/ruanjian/apache-maven-3.0.3-NEW/repository/org/slf4j/slf4j-log4j12/1.7.32/slf4j-log4j12-1.7.32.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:/D:/ruanjian/apache-maven-3.0.3-NEW/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.14.1/log4j-slf4j-impl-2.14.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]

2.1 继续跟下去 slf4j-log4j12 这么抢手,好几处都用到了它

spring-boot-starter-log4j2 依赖的是这个版本log4j-slf4j-impl

  1. SLF4J: Class path contains multiple SLF4J bindings.
  2. SLF4J: Found binding in [jar:file:/D:/ruanjian/apache-maven-3.0.3-NEW/repository/org/slf4j/slf4j-log4j12/1.7.32/slf4j-log4j12-1.7.32.jar!/org/slf4j/impl/StaticLoggerBinder.class]
  3. SLF4J: Found binding in [jar:file:/D:/ruanjian/apache-maven-3.0.3-NEW/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.14.1/log4j-slf4j-impl-2.14.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
  4. SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
  5. SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
  6. log4j:WARN No appenders could be found for logger (org.springframework.boot.ApplicationServletEnvironment).
  7. log4j:WARN Please initialize the log4j system properly.
  8. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
  9.  
  10. . ____ _ __ _ _
  11. /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
  12. ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
  13. \\/ ___)| |_)| | | | | || (_| | ) ) ) )
  14. ' |____| .__|_| |_|_| |_\__, | / / / /
  15. =========|_|==============|___/=/_/_/_/
  16. :: Spring Boot :: (v2.5.3)

  3.1 问题找到了,解决方案开始实施:

我这里就把对应的日志:排除掉了,目前排除的是这个:

spring-boot-starter-log4j2 依赖的是这个版本log4j-slf4j-impl   ,百度到的消息说这是个桥接包

日志框架:slf4j
日志实现:log4j2
桥接包:log4j-slf4j-impl

桥接包log4j-slf4j-impl起到适配的作用,因为市面上的日志实现互不兼容,日志框架slf4j要想适用于日志实现log4j2,就需要使用桥接包

具体啥情况咱也不太懂,反正我是认为排除一个依赖就该能运行了吧? 当时是在这里

  1. spring-boot-starter-web 进行的依赖排除,我发现并没有排除掉依赖,我就百度搜了一下,然后从springboot的基础上进行排除
  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter</artifactId>
  4. <exclusions>
  5. <exclusion>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-logging</artifactId>
  8. </exclusion>
  9. </exclusions>
  10. </dependency>

  依赖排除掉之后发现并没有达到预期的结果,还是这样,除了爆红的几条明晃晃的信息之外,没有其他的消息了,调用输出的日志信息也没有正常显示出来,通过debug也没有异常,我慌了,

然后进行百度,

  1. No appenders could be found for logger (org.springframework.boot.ApplicationServletEnvironment).
  1. 这条有效信息进行百度的结果都是spring的方式启动的,然后都是提示让本地加logproperties文件,尝试的加上了,结果还是老样子。
  1. 第二条有效信息进行百度:
  1. Please initialize the log4j system properly.
  1. log4j:WARN No appenders could be found for logger (org.springframework.boot.ApplicationServletEnvironment).
  2. log4j:WARN Please initialize the log4j system properly.
  3. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

  (54条消息) No appenders could be found for logger_u013412790的专栏-CSDN博客

按照博客的说明,我按照第二条的的方式,把配置加到项目最上方

  1. <dependency>
  2. <groupId>org.apache.logging.log4j</groupId>
  3. <artifactId>log4j-1.2-api</artifactId>
  4. <version>2.8.2</version>
  5. </dependency>

启动之后,发现日志能正常打印出来了,心里别提多高兴了!

接下来,看看是否还需要配置文件,把配置文件删除,发现还能正常使用。到此处问题已经解决。

最后:不光要解决问题,以后遇到类似的问题要知道怎么解决和排查,要知其人并知其所以然。

找到了官方网站:http://www.slf4j.org/manual.html

日志的实现框架大概有以下几种:那么 slf4j-log4j12是哪个日志框架呢?

点击进去发现说: http://logging.apache.org/log4j/1.2/index.html

2015年8月5日,伐木服务项目管理委员会宣布Log4j 1.x已结束使用。有关公告的完整文本,请参阅阿帕奇博客。建议 Log4j 1 的用户升级到阿帕奇日志 4j 2

点进去:http://logging.apache.org/log4j/2.x/index.html

看导入pom是这样导入的

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.apache.logging.log4j</groupId>
  4. <artifactId>log4j-api</artifactId>
  5. <version>2.14.1</version>
  6. </dependency>
  7. <dependency>
  8. <groupId>org.apache.logging.log4j</groupId>
  9. <artifactId>log4j-core</artifactId>
  10. <version>2.14.1</version>
  11. </dependency>
  12. </dependencies>

  --------------------------------------------------------------------------------------------------------------------------

上面的因为日志找不到而导致的异常,今天我就想把日志集成到

  1. log4j2版本上去,发现了奇怪的一幕,目前还是两个实现类,而且实现的是随机使用一个实现类
  1. SLF4J: Class path contains multiple SLF4J bindings.
  2. SLF4J: Found binding in [jar:file:/D:/ruanjian/apache-maven-3.0.3-NEW/repository/ch/qos/logback/logback-classic/1.2.4/logback-classic-1.2.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
  3. SLF4J: Found binding in [jar:file:/D:/ruanjian/apache-maven-3.0.3-NEW/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.14.1/log4j-slf4j-impl-2.14.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
  4. SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
  5. SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]

  配置输出日志:

logging.level.root=INFO
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36}[%line] TraceId[%X{PFTID}] - %msg%n

解决springboot启动日志异常问题的更多相关文章

  1. 解决spring-boot启动异常Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean

    第一种: 需要在主类头加上  @EnableAutoConfiguration 第二种: pom文件是否加了 <dependency> <groupId>org.mybatis ...

  2. 解决spring-boot启动中碰到的问题:Cannot determine embedded database driver class for database type NONE

    问题 如下: 2017-07-16 08:50:57.436  INFO 13524 --- [           main] c.p.p.web.PointshopWebApplication   ...

  3. 解决springboot启动失败问题:Unable to start embedded container;

    将一个springboot项目导入到eclipse后,启动时报错Unable to start embedded container,以下时全部错误信息: Application startup fa ...

  4. springboot启动报异常,Failed to load property source from location 'classpath:/application.yml'

    学习springboot,在启动时抛出下图异常 往下看异常信息,找到异常的具体位置 找到application.yml文件的对应位置,发现params配置前面多了空格 去掉空格重新启动,可以了 写代码 ...

  5. 解决spring-boot启动中碰到的问题:Cannot determine embedded database driver class for database type NONE(转)

    问题 如下: 2017-07-16 08:50:57.436  INFO 13524 --- [           main] c.p.p.web.PointshopWebApplication   ...

  6. 清理忽略springboot控制台启动的banner和启动日志

    清理忽略springboot控制台启动的banner和启动日志 1.springboot的banner spring: main: banner-mode: off 2.mybatis-plus的ba ...

  7. SpringBoot使用MongoDB异常问题

    一 环境介绍 SpringBoot1.5.13.RELEASE(本地) Spring Data MongoDB Java 8 MongoDB(青云) 二 问题描述 使用Studio3T或者Compas ...

  8. springboot启动的时候日志缺少Mapping日志等

    发现启动springboot日志不全 缺失启动日志如: 正常启动日志 解决办法: 更换较低版本的spring boot父级依赖. <parent> <groupId>org.s ...

  9. 项目总结10:通过反射解决springboot环境下从redis取缓存进行转换时出现ClassCastException异常问题

    通过反射解决springboot环境下从redis取缓存进行转换时出现ClassCastException异常问题 关键字 springboot热部署  ClassCastException异常 反射 ...

随机推荐

  1. sql常用的统计公式

    hivesql中max,min函数不能作用于多列,因此在有上下门限区间限制时多用公式直接计算. max(x,y)=(x+y+ABS(x-y))/2 min(x,y)=(x+y-ABS(x-y))/2 ...

  2. Less-(5~7) error based

    Less-5: 核心语句: 我们注意到,当输入正确时,并不能获得有价值的回显.好在出现错误时,会爆出错误内容: 于是,使用报错注入: 1'  and updatexml(1,concat(0x7e,( ...

  3. [Git系列] Git 基本概念

    版本控制系统 版本控制系统是一种帮助软件开发者实现团队合作和历史版本维护的软件,一个版本控制系统应具备以下列出的这几个基本功能: 允许开发者并发工作: 不允许一个开发者覆写另一个开发者的修改: 保存所 ...

  4. java中this关键字总结

    1.this是一个引用,也是一个变量,存储在JVM堆内存的Java对象内部. 2.this变量中保存的内存地址指向自身. 3.this可以在实例方法中使用,this指向当前正在执行这个动作的对象(th ...

  5. 【二食堂】Beta - 设计和计划

    Beta设计和计划 需求再分析 根据助教.老师.用户以及各个团队PM的反馈意见,我们的项目目前有以下问题: 功能不完整 实用价值不高 两方面的缺陷,所以在Beta阶段,我们工作的中心还是完成项目规划中 ...

  6. 通过Nacos动态刷新Spring Cloud Gateway的路由

    通过Nacos动态刷新Spring Cloud Gateway的路由 一.背景 二.解决方案 三.实现功能 四.实现步骤 1.网关服务的实现 1.pom文件 2.bootstrap.yml配置文件 3 ...

  7. java监控JVM的内存使用情况等

    以下的程序监控参数的代码,有些是从网络上获取的,此处进行一个记录是为了以后如果要用到方便记录. 1.引入jar包,为了获取一些cpu的使用率等信息 <dependency> <gro ...

  8. 2021.9.20考试总结[NOIP模拟57]

    (换个编辑器代码就SB地不自动折叠了.. T1 2A 考察快读的写法. $code:$ T1 #include<bits/stdc++.h> #define scanf SCANF=sca ...

  9. 【Golang详解】go语言中并发安全和锁

    go语言中并发安全和锁 首先可以先看看这篇文章,对锁有些了解 [锁]详解区分 互斥锁.⾃旋锁.读写锁.乐观锁.悲观锁 Mutex-互斥锁 Mutex 的实现主要借助了 CAS 指令 + 自旋 + 信号 ...

  10. numpy数组的计算

    1.数组的形状 查看数组的形状: import numpy as np a = np.array([[1, 2, 3, 4, 5], [5, 6, 7, 8, 9]]) print(a.shape) ...