1
這是pom.xml的要點。 我使用的查詢DSL版本3.6.2
Spring數據Jpa查詢DSL Q Entityclasses not generating
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-core</artifactId>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>2.2.4</version>
<configuration>
<defaultOutputDirectory>
${project.build.directory}/generated-sources
</defaultOutputDirectory>
<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>${mapstruct.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>maven-apt-plugin</artifactId>
<version>1.0.2</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
<configuration>
<!-- Specifies the directory in which the query types are generated -->
<outputDirectory>target/generated-sources/querydsl</outputDirectory>
<!-- States that the APT code generator should look for JPA annotations -->
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
每當我運行mvn乾淨安裝,此異常信息時
[ERROR] diagnostic: C:\Users\users\app\app-ims\app-ims-core\src\main\java\org\app\genesis\inventory\repo\ProductRepoImpl.java:6: error: cannot find symbol
import org.brightworks.genesis.inventory.model.QProduct;
^
symbol: class QProduct
location: package org.app.genesis.inventory.model
這裏是類的要點。
import com.mysema.query.jpa.impl.JPAQuery;
import com.mysema.query.types.ConstructorExpression;
import org.brightworks.genesis.inventory.dto.ProductDTO;
import org.brightworks.genesis.inventory.model.QProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import javax.persistence.EntityManager;
import java.util.List;
/**
*
*/
public class ProductRepoImpl implements ProductRepoCustom {
@Autowired
private EntityManager em;
@Override
public Page<ProductDTO> search(String term, Pageable pageable) {
JPAQuery query = new JPAQuery(em);
QProduct product = QProduct.product;
模型和回購在同一個項目中,但是沒有生成Q實體類。我該如何解決?
爲什麼要同時使用Maven的處理器插件和Maven的的apt-插件?他們都爲mvn提供APT支持。其中一個應該就夠了。 – 2015-04-05 19:34:33
@TimoWestkämper因爲我使用的框架之一,MapStruct需要它。 – user962206 2015-04-06 01:58:43