Spring 由于缺少 QClass,引导无法编译

Spring boot not compiling due to QClass missing

大家好,我是 spring 引导新手,我一直在尝试将 querDSL 集成到我的项目中,但每次我打包它时都会出现错误。例如,它会说我的 QClasses 将不存在,即使它们已通过 Maven 正确导入。我尝试了不同版本的 queryDSL,但没有找到解决方案。我认为这是我的 pom 文件的问题,尽管我不确定,因为我已经按照 Baeldung 制作的教程进行操作。任何建议都会有所帮助,谢谢。

我的确切错误

Error:(11, 8) java: cannot access com.querydsl.core.types.OrderSpecifier
  class file for com.querydsl.core.types.OrderSpecifier not found
This is in the Repo class below

我的Pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.1.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>rc</groupId>
<artifactId>springboot-mongodb-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot-mongodb-demo</name>
<description>Demo project for Spring Boot with Mongo Db</description>

<properties>
    <java.version>1.8</java.version>
    <querydsl.version>4.1.3</querydsl.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

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

    <dependency>
        <groupId>com.mysema.querydsl</groupId>
        <artifactId>querydsl-mongodb</artifactId>
        <version>3.6.6</version>
    </dependency>
    <dependency>
        <groupId>com.mysema.querydsl</groupId>
        <artifactId>querydsl-apt</artifactId>
        <version>3.6.6</version>
    </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>
                            org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor
                        </processor>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

我的回购层代码

    package rc.springbootmongodbdemo;

import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.stereotype.Repository;

import java.util.*;

@Repository
public interface HotelRepository extends MongoRepository<Hotel, String>, QuerydslPredicateExecutor<Hotel> {
    Hotel findByID(String id);
    List<Hotel> findByPricePerNightLessThan(int maxPrice);

    @Query(value = "{address.city:?0}")
    List<Hotel> findByCity(String city);
}

检查之前回答的这个问题 Spring Boot+JPA+QueryDSL=OrderSpecifier not found

也通过这个 https://www.baeldung.com/intro-to-querydsl

解决方案: 我有一个正在扩展 MongoRepository 的存储库 class。我传递了以下内容

public interface HotelRepository extends MongoRepository<Hotel, String>, QuerydslPredicateExecutor<Hotel>{

删除后: QuerydslPredicateExecutor

我的错误消失了,我的程序又开始 运行 了。 我觉得 querydslpredicateexecutor 可能是一种较旧的代码格式,它没有编译到我的新版本中。只是一个理论。