Spring Boot+JPA+QueryDSL=未找到 OrderSpecifier

我有这个pom.xml:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.5.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>com.mysema.querydsl</groupId>
        <artifactId>querydsl-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>com.mysema.querydsl</groupId>
        <artifactId>querydsl-apt</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.6.1</version>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.16.8</version>
    </dependency>
    <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <scope>runtime</scope>
    </dependency>
</dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>com.mysema.maven</groupId>
                <artifactId>apt-maven-plugin</artifactId>
                <version>1.1.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/generated-sources/java</outputDirectory>
                            <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

这个实体:

@Entity
@Data
@Builder
public class DataDto {
    @Id
    private String id;
    private String name;
}

这个回购:

public interface DataRepo extends  JpaRepository <DataDto,String>, QueryDslPredicateExecutor<DataDto> {
}

我收到此错误:

Error:(9, 8) java: cannot access com.mysema.query.types.OrderSpecifier
  class file for com.mysema.query.types.OrderSpecifier not found

听起来我错过了依赖关系或其他东西??

我一直在关注这些链接来提供帮助:http://www.querydsl.com/static/querydsl/latest/reference/html/ch02.html#jpa_integration http://spring.io/blog/2011/04/26/advanced-spring-data-jpa-specifications-and-querydsl


答案 1

在项目中添加以下依赖项

            <dependency>
                <groupId>com.querydsl</groupId>
                <artifactId>querydsl-jpa</artifactId>
                <version>4.0.3</version>
            </dependency>

根据您的 JPA 版本的版本号。


答案 2

我的弹簧引导版本是2.0.5.RELEASE我通过添加此依赖项解决了这个问题

<!-- https://mvnrepository.com/artifact/com.mysema.querydsl/querydsl-jpa -->
<dependency>
    <groupId>com.mysema.querydsl</groupId>
    <artifactId>querydsl-jpa</artifactId>
    <version>2.0.7</version>
</dependency>

推荐