开发者社区 问答 正文

maven多模块SpringBoot该如何配置log4j2?:配置报错 

app是入口模块,依赖关系分别是app->user->common 顶层pom.xml的依赖

<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </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> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> </dependency>

</dependencies>

如果把log4j2.xml放在common等子模块,程序将会卡死,无错误提示,不能启动。 只有把log4j2.xml删掉,或者去除顶层pom.xml
<exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions>
都能让项目启动,但无法记录日志到文件。   请问,多模块下,该怎么做日志配置?

展开
收起
kun坤 2020-06-02 16:50:21 1066 分享 版权
1 条回答
写回答
取消 提交回答
  • 每个项目做自己的,common里面所有都是provide尽量不要有任何的强依赖。######spring boot 默认使用logback记录日志。logback是继承与log4J的不需要额外配置.如果更改log的配置,直接在application.properties或者yml中更改配置即可

    2020-06-02 16:50:28
    赞同 展开评论