SpringBoot Couchbase集成 [英] SpringBoot Couchbase Integration

查看:294
本文介绍了SpringBoot Couchbase集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用QueryDslPredicateExecutor接口为UserTask实体创建一个可过滤列表,因此查询字符串中给出的参数将被自动处理为谓词.

I want to make a filterable list of my UserTask entity with the QueryDslPredicateExecutor interface, so the parameters given in the query string will be autoprocessed into a Predicate.

我有以下类/接口

public interface UserTaskQuerydslRepository extends CrudRepository<UserTask, String>, 
    QueryDslPredicateExecutor<UserTask>, QuerydslBinderCustomizer<QUserTask> {

    @Override
    default void customize(QuerydslBindings bindings, QUserTask userTask) {
        ...
    }
}

UserTask是我的代表(couchbase)模型的类

UserTask is my class that represents the (couchbase) model

@QueryEntity
@Document(expiry = 0)
public class UserTask {

    @Id
    private String id;

    ...
}

如果我使用@QueryEntity注释此类,则Maven会为我生成QUserTask类

If i annotate this class with @QueryEntity then Maven generates the QUserTask class for me

@Generated("com.mysema.query.codegen.EntitySerializer")
public class QUserTask extends EntityPathBase<UserTask> {

    private static final long serialVersionUID = 493434469L;

    public static final QUserTask userTask = new QUserTask("userTask");

    public final StringPath id = createString("id");

    ...

    public QUserTask(String variable) {
        super(UserTask.class, forVariable(variable));
    }

    public QUserTask(Path<? extends UserTask> path) {
        super(path.getType(), path.getMetadata());
    }

    public QUserTask(PathMetadata<?> metadata) {
        super(UserTask.class, metadata);
    }

}

要生成QUserTask,我将以下行添加到pom.xml

To generate QUserTask i added the following lines to pom.xml

<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/apt</outputDirectory>
                <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
                <processor>com.mysema.query.apt.QuerydslAnnotationProcessor</processor>
            </configuration>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>com.mysema.querydsl</groupId>
            <artifactId>querydsl-apt</artifactId>
            <version>3.4.3</version>
        </dependency>
    </dependencies>
</plugin>

在该项目中,我们既有JPA实体又有沙发床实体,这就是为什么我在那里有JPAAnnotationProcessor.

In the project we have both JPA entities and couchbase entities, that's why i have the JPAAnnotationProcessor there.

如果我这样运行应用程序,则会出现以下错误:

If i run the application like this i get the following error:

org.springframework.data.mapping.PropertyReferenceException:否 找到类型为UserTask的属性findAll!

org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type UserTask!

我尝试用@NoRepositoryBean注释UserTaskQuerydslRepository,它解决了我的findAll问题,但是当我尝试将这个存储库注入到资源(或控制器,JHipster称其为Resource)时,出现以下错误

I tried to annotate my UserTaskQuerydslRepository with @NoRepositoryBean, it solved my findAll problem, but when i tries to @Inject this repository to a Resource (or controller, JHipster calls it Resource) i get the following error

没有任何类型为[.UserTaskQuerydslRepository]的合格Bean 找到依赖项:至少需要1个符合条件的bean 自动关联此依赖项的候选对象.依赖注释: {@ javax.inject.Inject()}

No qualifying bean of type [.UserTaskQuerydslRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.inject.Inject()}

谁能帮助我我做错了什么事?

Can anyone help me what did I do wrong?

推荐答案

正如@ mp911de在评论中所说,Spring Data Couchbase不支持QueryDsl,这说明了为什么无法创建bean的原因.

As @mp911de said in his comment, Spring Data Couchbase doesn't have support for QueryDsl, which explains why the bean cannot be created.

阅读文档时,我可以看到您的困惑来自何处.第5章是所有Spring Data store实现的通用内容.所有商店文档都有一章具有相同内容,通常讨论存储库基础知识.因此,它可以提及不在特定实现中的内容.

I can see where your confusion comes from when reading the doc. Chapter 5 is the content common to all Spring Data store implementations. All store documentations have one chapter with that same content, which generically talk about the repository basics. So it can mention things that are not in a particular implementation.

您链接的部分的第一句话甚至暗示了它:

The first sentence of the section you linked even hints at it:

几个Spring Data模块通过QueryDslPredicateExecutor与Querydsl集成.

Several Spring Data modules offer integration with Querydsl via QueryDslPredicateExecutor.

不幸的是,不是几个,而是Spring Data Couchbase模块.

Several, but not the Spring Data Couchbase module unfortunately.

这篇关于SpringBoot Couchbase集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆