我發現有一個像我的許多問題,但從來沒有過的答案,使Querydsl我春季啓動項目。 這是我pom.xml
依賴和插件:JpaRepository Querydsl:QCLASS不產生
<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
但它不工作,不知道往哪裏放那。 - 我試圖querydsl的許多版本,但在評論中提到一起,你還需要配置用於查詢DSL Maven的易插件,所以在POM插件中添加該錯誤是相同
QueryDSL和Spring Boot的版本可能會造成這個問題。 對查詢dsl及其依賴項嘗試spring引導1.4.4和3.7.4。 –
@MuhammadFaisalHyder可惜沒有。它不工作 – Kenji