Spring boot log4j maven Jar找不到解决

在升级SpringBoot版本后遇到了依赖版本缺失的问题,具体表现为找不到spring-boot-starter-log4j的Jar包。通过查询发现SpringBoot 1.4.2.RELEASE不再支持Log4j,官方推荐使用Logback。本文介绍了如何正确配置并使用Logback。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题

把Springboot版本升级了下,运行发现报了这样一个错误:

'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-log4j:jar is missing.

报错的提示是spring-boot-starter-log4j这个Jar找不到。
Maven是如下配置:

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

<dependencies>

    ........

    <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>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j</artifactId>
    </dependency>
</dependencies>

解决

到Maven respository查询了下,Log4j最新版本为1.3.8.RELEASE版本,而最新SpringBoot版本为1.4.2.RELEASE,对Log4j不提供Jar包,所以找不到这个版本的Jar包

Maven  repository

SpringBoot本身集成了日志系统,因此采用官方推荐的Logback。
Logback已经集成到spring-boot-starter里面了,所以不需要再配置,直接就可以使用。

1、代码中输出log:

private final Logger logger = LoggerFactory.getLogger(this.getClass());  
logger.debug("This is a debug message");  
logger.info("This is an info message");  
logger.warn("This is a warn message");  
logger.error("This is an error message");  

2、文件输出log需要在application.properties进行配置:

logging.file=log.log  
logging.level.com.xiaofangtech.sunt.controller = debug  
logging.level.com.xiaofangtech.sunt.helper = warn  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值