在我的项目中,我们使用了 Hibernate (JPA) 元模型生成器来使我们的 Criteria 查询类型安全。这一切在我们的应用程序中运行良好,但是,当我们使用我们的 IDE 在该 Maven 模块中运行 JUnit 测试时,它们现在失败并出现以下错误:-Error:java: Annotation processor 'org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor' not found
我猜这是由于我们生成的类中的以下内容:-@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(MyEntity.class)
当 Maven 将测试作为我们构建过程的一部分运行时,它们就可以毫无问题地运行。
我怀疑我在 IDE 的设置中遗漏了一些东西,即 IntelliJ IDEA 14。有什么想法吗?还是我在 Maven 中做错了什么? :-
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>2.1.0</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>4.3.4.Final</version>
<optional>true</optional>
</dependency>
</dependencies>
</plugin>
最佳答案
我升级到 后遇到了类似的问题IntelliJ IDEA 14.1.2 .对我来说,以下操作解决了这个问题:
Go to Settings > Build, Execution, Deployment > Compiler > Annotation Processors.
在此配置面板的左侧,我有一个
Annotation profile
对于我项目中的每个 Maven 模块。我自己没有设置这些配置文件:也许它们是由 IDE
推断的.我不知道,但在其中一些注释配置文件中,启用注释处理 flag
已启用。此外,在某些情况下, JPAMetaModelEntityProcessor 在这里被明确列为注解处理器。之后 删除 注释处理器 从配置文件中禁用checkbox
,错误消失,我的测试成功运行。
关于maven - 在添加 Hibernate 元模型类后在 Maven 模块中使用 IntelliJ 时,JUnit 测试失败并出现 Java 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27412287/