SpringBoot Couchbase Integration

为君一笑 提交于 2019-12-24 06:48:49

问题


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.

I have the following classes/interfaces

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

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

UserTask is my class that represents the (couchbase) model

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

    @Id
    private String id;

    ...
}

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);
    }

}

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>

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: No property findAll found for type UserTask!

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

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?


回答1:


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

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:

Several Spring Data modules offer integration with Querydsl via QueryDslPredicateExecutor.

Several, but not the Spring Data Couchbase module unfortunately.




回答2:


2016. 07. 11. : After some research, and according to answers by @mp911de, and @simon-baslé we know that Spring Data Couchbase doesn't have support for QueryDsl yet.

I found a workaround for the problem that i wanted to solve (dynamic querying, aka. filters on a list and make it pageable)

https://github.com/TeamWanari/couchbase-query-executor



来源:https://stackoverflow.com/questions/38153365/springboot-couchbase-integration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!