写一个简单的类
package com.example.demo.controller;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RequestMapping("test")
@RestController
@Slf4j
public class TTController {
@RequestMapping("/log")
public String getT() {
log.info("log");
return "success";
}
}
引入注解@Slf4j编译之后查看class文件反编译,反编译文件如下:
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package com.example.demo.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RequestMapping({"test"})
@RestController
public class TTController {
private static final Logger log = LoggerFactory.getLogger(TTController.class);
public TTController() {
}
@RequestMapping({"/log"})
public String getT() {
log.info("log");
return "success";
}
}
发现lombok 使用APT技术已经生成了private static final Logger log = LoggerFactory.getLogger(TTController.class);
查看info的实现的时候发现有多个实现点击F7 进入发现进入的是Logger实现
public final class Logger implements org.slf4j.Logger, LocationAwareLogger, AppenderAttachable<ILoggingEvent>, Serializable {
实现逻辑如下:
<