问题
把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包
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