我正在尝试使用 lombok 项目生成一个记录器,如示例 here 。
当我进入intelliJ时,我输入的log
没有代码完成。我收到以下错误:
代码摘录:
package com.example.clement.recipeproject.bootstrap;
import com.example.clement.recipeproject.domain.*;
import com.example.clement.recipeproject.repositories.CategoryRepository;
import com.example.clement.recipeproject.repositories.RecipeRepository;
import com.example.clement.recipeproject.repositories.UnitOfMeasureRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@Slf4j
@Component
public class DevBootstrap implements ApplicationListener<ContextRefreshedEvent> {
private CategoryRepository categoryRepository;
private UnitOfMeasureRepository unitOfMeasureRepository;
private RecipeRepository recipeRepository;
public DevBootstrap(CategoryRepository categoryRepository, UnitOfMeasureRepository unitOfMeasureRepository, RecipeRepository recipeRepository) {
this.categoryRepository = categoryRepository;
this.unitOfMeasureRepository = unitOfMeasureRepository;
this.recipeRepository = recipeRepository;
}
// returns List<Recipe>
private List<Recipe> getRecipes() {
log.debug("I am a debug message");
*** 更新:
添加了更多照片以显示 slf4j
日志即将出现,但之后没有适当的方法。
当我跳进@Slf4j 时,我明白了。
注释处理器已打开,但不确定配置是否正确。
最佳答案
您是否将 slf4j 依赖项添加到 build.gradle 中,如下所示
dependencies {
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
}
关于java - 无法将 Slf4j 与 lombok 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47047726/