[英]How to add querydsl-mongodb to Spring Boot Gradle 5.6.1 project
I am trying to create dynamic query to a mongo database from spring boot gradle project.我正在尝试从 spring boot gradle 项目创建对 mongo 数据库的动态查询。 My gradle version: 5.6.1我的gradle版本:5.6.1
Here is my build.gradle file:这是我的 build.gradle 文件:
plugins {
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'com.onssoftware'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
// https://mvnrepository.com/artifact/com.querydsl/querydsl-mongodb
compile group: 'com.querydsl', name: 'querydsl-mongodb', version: '4.2.2'
// https://mvnrepository.com/artifact/com.querydsl/querydsl-apt
compile group: 'com.querydsl', name: 'querydsl-apt', version: '4.2.2'
//annotationProcessor group: 'com.querydsl', name: 'querydsl-apt', version: '4.2.2'
annotationProcessor "com.querydsl:querydsl-apt:4.2.2"
//annotationProcessor("org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor")
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
My application.properties file:我的 application.properties 文件:
spring.data.mongodb.username = user
spring.data.mongodb.password = pass
spring.data.mongodb.host = 172.17.0.2
spring.data.mongodb.port = 27017
spring.data.mongodb.database = test_db
Problem is: Q classes are not generating for my Documents.问题是:没有为我的文档生成 Q 类。 Any suggestion welcome.欢迎任何建议。 Thanks.谢谢。
Possibly, duplicated with Java QueryDsl code generation does not generate Q class可能,用Java QueryDsl重复生成代码不会生成Q类
And maybe it's because of Gradle version: try to check this https://github.com/ewerk/gradle-plugins/issues/112也许是因为 Gradle 版本:尝试检查这个https://github.com/ewerk/gradle-plugins/issues/112
Or you forget to include或者你忘记包括
compile group: 'org.mongodb.morphia', name: 'morphia', version: '1.3.2'
Meanwhile, I'll try to reproduce using @viktorgt repository同时,我将尝试使用@viktorgt存储库进行重现
I made it working by adding both @Document and @Entity annotation.我通过添加 @Document 和 @Entity 注释使其工作。
import org.springframework.data.mongodb.core.mapping.Document;
import javax.persistence.Entity;
@Document
@Entity
public class MCQ {}
My build.gradle file is like:我的 build.gradle 文件是这样的:
// https://mvnrepository.com/artifact/org.hibernate/hibernate-annotations
compile group: 'org.hibernate', name: 'hibernate-annotations', version: '3.5.6-Final'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
// https://mvnrepository.com/artifact/com.querydsl/querydsl-mongodb
compile group: 'com.querydsl', name: 'querydsl-mongodb', version: '4.2.2'
// https://mvnrepository.com/artifact/com.querydsl/querydsl-apt
annotationProcessor "com.querydsl:querydsl-apt:4.2.2:jpa", "org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final"
// https://mvnrepository.com/artifact/com.google.code.morphia/morphia
//annotationProcessor group: 'com.google.code.morphia', name: 'morphia', version: '0.104'
// https://mvnrepository.com/artifact/org.mongodb.morphia/morphia
//annotationProcessor group: 'org.mongodb.morphia', name: 'morphia', version: '1.3.2'
//annotationProcessor("org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor")
My gradle version: 5.6.2我的gradle版本:5.6.2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.