Spring Boot omits the creation of logs through Slf4j provided by lombok

Above, Spring Boot extracted the step of declaring logs and made it into a reusable class. We wrote a public class for creating logs, but naturally someone will write it well for such a simple thing.

lombok has provided this tool

First we need to add this piece of code to pom.xml

<dependency>
	<groupId>org.projectlombok</groupId>
	<artifactId>lombok</artifactId>
</dependency>

Bring lombok in
Insert image description here
, then find the class that you want to use the log before, remove the inherited code, we no longer need to write it ourselves,
and add an annotation at the top.

@Slf4j

Then we can use the log normally in this class. The attribute name is also called log.
Insert image description here
Then we start the project again
Insert image description here
. Then we access the interface.
Insert image description here
Then we look back at the editor. We
Insert image description here
can see that there is no problem. After all, this is just a small function.

Guess you like

Origin blog.csdn.net/weixin_45966674/article/details/132893276