Building with Lombok's @Slf4j and Eclipse: Cannot find symbol log

ε祈祈猫儿з 提交于 2019-12-22 01:26:43

问题


I have the lombok plugin in Eclipse and enabled annotation processing in Eclipse under java compiler, but still it is unable to recognize the log statements when I use @Slf4j annotation.

Do we have to make any other settings?


回答1:


You also have to install Lombok into Eclipse.

See also this answer on how to do that or check if Lombok is installed correctly.

Full Disclosure: I am one of the Project Lombok developers.




回答2:


I got the same error even after Lombok was installed. For me the solution was to add another lombok annotation (i used @Data) to my class after which the eclipse errors went away. Perhaps this force refreshed some cache.

Of course, I simply deleted the @Data annotation afterwards.




回答3:


I also faced the similar issue on log and @Slf4j on my STS environment. To resolve this, here is what I did on spring tool suite (sts-4.4.0.RELEASE) and lombok-1.18.10.jar (current latest version available in mavenrepository).

  1. If having maven project, ensure lombok dependency added to it. Else you need manually add the jar to your project classpath.

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

  2. Clean build the maven application. This will download lombok jar in your .m2 location by default from maven repository. The path would be org\projectlombok\lombok\1.18.10\

  3. Now open command prompt and navigate to the lombok path and execute command java -jar lombok-1.18.10.jar

    C:\xxx\xxx\org\projectlombok\lombok\1.18.10>java -jar lombok-1.18.10.jar

  4. Opens up lombok dialog box. If see message Can't find IDE Click Specify location... Provide the path to your STS root location

    My case it is C:\apps\sts-4.4.0.RELEASE\SpringToolSuite.exe

    Install/Update

  5. Install successful Click Quit Installer

  6. Now in explorer navigate to your STS root path. C:\apps\sts-4.4.0.RELEASE\ We see lombok.jar placed in the sts root path Now edit in notepad SpringToolSuite4.ini file We see following appended at the end

    -javaagent:C:\apps\sts-4.4.0.RELEASE\lombok.jar

  7. Start STS using SpringToolSuite4.exe Clean, rebuild your project.




回答4:


this got the fix to me by adding the slf4j dependency, Lombok can identify the slf4j but does not get the download, this is true for java project if you are using spring boot then slf4j comes by default.

here are my dependencies

    <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.25</version>
    </dependency>




    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.6</version>
        <scope>provided</scope>
    </dependency>


来源:https://stackoverflow.com/questions/16627751/building-with-lomboks-slf4j-and-eclipse-cannot-find-symbol-log

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!