我有一个maven项目,可以从命令行构建,没有任何问题。但是,当我使用IntelliJ构建它时,我得到了错误:
java: FileName.java:89: cannot find symbol
symbol : variable log
在java文件中没有定义或导入日志,但存在
@Slf4j
final public class FileName {
语句,该语句应定义日志类。
在项目结构窗口中,类用于:
Maven: org.slf4j:jcl-over-slf4j:1.6.1
Maven: org.slf4j:slf4j-api:1.6.6
Maven: org.slf4j:slf4j-log4j12:1.6.6
Maven: org.slf4j:slf4j-simple:1.6.6
列在库下面,并表示已下载并可用。
你知道为什么要用maven通过命令行构建,而不是通过IntelliJ构建吗?以及如何解决这个问题?
发布于 2019-05-15 07:52:46
这不是OP的问题,但对于尝试了所有方法都没有成功的其他人来说:
我也有类似的症状。每当我在mvn clean
之后构建时,它都找不到log
、getXYZ()
、builder()
或任何东西。
[ERROR] symbol: variable log
[ERROR] location: class com.example.MyClass
[ERROR] /Path/To/Some/Java/src/main/com/example/MyClass.java:[30,38] cannot find symbol
[ERROR] symbol: method builder()
[ERROR] location: class com.example.MyClass
在阅读了我能找到的关于QueryDSL/JPA/Hibernate/Lombok/IntelliJ/Maven问题的所有答案都无济于事之后,我发现罪魁祸首是在静态字段上注释的 @Getter
方法的单个静态导入。
Spring 1.15.14.Relase,Intellij 2019.1.1
@SpringBootApplication
public class BarApplication implements ApplicationContextAware {
@Getter
private static ApplicationContext applicationContext;
// ... start Spring application, and grab hold of ApplicationContext as it comes past
}
import ...
import static BarApplication.getApplicationContext;
@Slf4j
public class IMakeItAllFail {
public IMakeItAllFail() {
log.info("{}", getApplicationContext());
}
}
@Slf4j
public class Foo {
Foo() {
log.info("I fail to compile but I have nothing to do with the other classes!");
}
}
https://stackoverflow.com/questions/14866765
复制相似问题