我发现有很多像我这样的问题,但从来没有在我的 Spring-boot 项目中启用 Querydsl 的答案。
这是我的 pom.xml
依赖项和插件:
<properties>
<querydsl.version>3.7.4</querydsl.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-core</artifactId>
<version>${querydsl.version}</version>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${querydsl.version}</version>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>${querydsl.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
//added for QueryDsl
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>maven-apt-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
这是我的实体:
@Entity
@Table(name = "phone_table")
public class Phone {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long phoneId;
private String phoneName;
private String phoneBrand;
private String phoneManufacturer;
...
这是存储库:
@Repository
public interface MobileRepository extends JpaRepository<Phone,Long> ,QueryDslPredicateExecutor<Phone>{
}
我的项目没有运行,它是错误说
Did not find a query class ir.mtajik.entities.QPhone for domain class ir.mtajik.entities.Phone
和原因:无法创建 QPhone 类。我用谷歌搜索了很多。有很多像我这样的问题,但答案在我的情况下不起作用。我试过这些:
@Document
但它不起作用,不知道把它放在哪里。 最佳答案
当我更换处理器时,它对我有用。
所以你有它:
<configuration>
<outputDirectory>target/generated-sources</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
将其更改为:
<configuration>
<outputDirectory>target/generated-sources</outputDirectory>
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
希望这可以帮助 ;)
关于maven - JpaRepository Querydsl : Qclass not generates,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42255734/