0

I want to use the @Slf4j annotation, so I imported this dependency in my pom.xml file

<dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.29</version>
        </dependency>

but I have the error Cannot resolve symbol Slf4j

@Service
@Slf4j
@Transactional(readOnly = true)
public class PasswordResetTokenService {
..
}
Nuñito Calzada
  • 4,394
  • 47
  • 174
  • 301

2 Answers2

1

I believe @Slf4j annotation is not actually coming from Slf4j but from Lombok. please look at this link that seems to provide a very good template to start from https://howtodoinjava.com/spring-boot2/logging/logging-with-lombok/

if you look at the excerpt of Application.java. the import for the annotation is coming from lombok

import lombok.extern.slf4j.Slf4j;

Denounce'IN
  • 95
  • 1
  • 10
1

The annotation @Slf4j is a Lombok annotation and is not present in the slf4j dependency.

If you want to use this annotation instead of declaring a logger field, you will need to add an extra dependency to Lombok:

<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.10</version>
    <scope>provided</scope>
</dependency>

In case of Spring Boot, the parent POM might already specify the version. Then you don't need to declare the specific version anymore.

See:

https://projectlombok.org/features/log

https://projectlombok.org/api/lombok/extern/slf4j/Slf4j.html