我收到编译错误:
com/mycompany/hibernate5/Main.java:[10,46] cannot find symbol
symbol: class Customer_
location: package com.mycompany.hibernate5.sakila.domain
com/mycompany/hibernate5/Main.java:[11,46] cannot find symbol
symbol: class Address_
location: package com.mycompany.hibernate5.sakila.domain
2 errors
然而,当我删除mapstruct注释处理器时,它编译得很好。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<!-- <configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
</annotationProcessorPaths>
</configuration>-->
</plugin>
所以我认为mapstruct是在生成类之前扫描它们的?对此有何解决方案?
答案 0 :(得分:1)
问题是maven-compiler
只选择MapStruct注释处理器而不是生成Customer_
类的那个(假设它是Hibernate Metamodel Generator)。请查看annotationProcessorPaths的文档。
您有两种方法可以解决您的问题:
添加所有注释处理器的方式与添加MapStruct的方式相同:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<annotationProcessorPaths>
<!-- Here you add the other paths -->
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
在依赖项中添加MapStruct作为提供的依赖项(为了不与jar / war一起打包):
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
<scope>provided</scope>
</dependency>
我建议使用选项1,因为这样你就不会意外地使用某些注释处理器的传递依赖。
答案 1 :(得分:0)
我遇到了同样的问题。我最终使用了org.bsc.maven插件并使用了<includes>
。您还可以添加<defaultOutputDirectory>
。
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<includes>**/mapper/*.java</includes> <!--package where annotated mapper classes reside-->
<processors>
<processor>org.mapstruct.ap.MappingProcessor</processor>
</processors>
</configuration>
<executions>
<execution>
<id>process</id>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-maven-plugin</artifactId>
<configuration>
<includes>**/persistence/*.class</includes>
<excludes>**/persistence/*_.class</excludes>
<addDefaultConstructor>true</addDefaultConstructor>
<enforcePropertyRestrictions>true</enforcePropertyRestrictions>
</configuration>
<executions>
<execution>
<id>enhancer</id>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
答案 2 :(得分:0)
我将hibernate JPA modelgen jar添加到路径
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
<path>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.2.6.Final</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
现在它正在工作,谢谢