我想使用 Lombok 的记录器。我添加了@Slf4j注释,添加了依赖项,它说它无法解析符号log。Error:(5, 1) java: package org.slf4j does not exist
package a;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class a {
public static void main(String[] args) {
log.info("lala");
}
}
Run Code Online (Sandbox Code Playgroud)
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>a</groupId>
<artifactId>a</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
rzw*_*oot 23
您还需要将 slf4j 本身作为依赖项添加到您的项目中,方法是将其包含在您的 pom 文件中。所有在龙目岛的功能lombok.extern包共享此属性:它们有助于你使用一个库,是不是已经盒子的可用出来作为Java本身的一部分,并为所有的人,龙目岛本身并没有包括任何这些依赖关系。
应该像将以下块添加到您的pom.xml:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)