如何在SpringWebFlux中使用reactivequerydslpredicateexecutor

gab6jxml  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(882)

我试着用 ReactiveQuerydslPredicateExecutor 使用springwebflux,使用mysql数据库和r2dbc。故事延伸 ReactiveSortingRepository ,效果很好。但是如果我延长 ReactiveQuerydslPredicateExecutor 同样,它也不会编译。我正在启用r2dbc EnableR2dbcRepositories . 早在React包出现的前一天,人们就必须将“enablejparepositories”的基本包更改为相关的“q”包。但是我在这里找不到任何东西,上面说没有“findall方法”。
代码:

@Table("user")
@AllArgsConstructor
@NoArgsConstructor
@Data
@QueryEntity
public class User {

    @Id
    Long id;

    String name;

    String email;
}
@Repository
public interface UserRepository extends ReactiveSortingRepository<User, Long>, ReactiveQuerydslPredicateExecutor<User> {
}
@Configuration
@EnableR2dbcRepositories(repositoryBaseClass = ReactiveCrudRepository.class)
public class AppConfig {
}

错误:

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type User!
    at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:94) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:382) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:358) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at org.springframework.data.mapping.PropertyPath.lambda$from$0(PropertyPath.java:311) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at java.util.concurrent.ConcurrentMap.computeIfAbsent(ConcurrentMap.java:324) ~[na:1.8.0_211]
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:293) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:276) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at org.springframework.data.repository.query.parser.Part.<init>(Part.java:82) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at org.springframework.data.repository.query.parser.PartTree$OrPart.lambda$new$0(PartTree.java:251) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_211]
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) ~[na:1.8.0_211]
    at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) ~[na:1.8.0_211]
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_211]
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_211]
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_211]
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_211]
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_211]
    at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:252) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at org.springframework.data.repository.query.parser.PartTree$Predicate.lambda$new$0(PartTree.java:381) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_211]
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) ~[na:1.8.0_211]
    at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) ~[na:1.8.0_211]
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_211]
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_211]
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_211]
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_211]
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_211]
    at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:382) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:94) ~[spring-data-commons-2.3.6.RELEASE.jar:2.3.6.RELEASE]
    at org.springframework.data.r2dbc.repository.query.PartTreeR2dbcQuery.<init>(PartTreeR2dbcQuery.java:66) ~[spring-data-r2dbc-1.1.6.RELEASE.jar:1.1.6.RELEASE]
    ... 55 common frames omitted

编辑:

我的数据库连接(在application.properties中):

spring.r2dbc.url=r2dbc:mysql://127.0.0.1:3306/testdb
spring.r2dbc.username=root
spring.r2dbc.password=

my pom.xml:(我使用的是最新版本的所有内容,存在排除项,因为同一个包的版本冲突。年龄较大的除外。)

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
            <version>2.3.7.RELEASE</version>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-r2dbc</artifactId>
            <version>2.3.7.RELEASE</version>
            <exclusions>
                <exclusion>
                    <artifactId>reactor-core</artifactId>
                    <groupId>io.projectreactor</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>5.3.2</version>
            <exclusions>
                <exclusion>
                    <artifactId>spring-beans</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-tx</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-core</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.github.jasync-sql</groupId>
            <artifactId>jasync-r2dbc-mysql</artifactId>
            <version>1.1.4</version>
            <exclusions>
                <exclusion>
                    <artifactId>r2dbc-spi</artifactId>
                    <groupId>io.r2dbc</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>reactor-core</artifactId>
                    <groupId>io.projectreactor</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>kotlin-stdlib</artifactId>
                    <groupId>org.jetbrains.kotlin</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>kotlin-stdlib-common</artifactId>
                    <groupId>org.jetbrains.kotlin</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>netty-handler</artifactId>
                    <groupId>io.netty</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>netty-transport</artifactId>
                    <groupId>io.netty</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.16</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-sql-spring</artifactId>
            <version>4.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-reflect</artifactId>
            <version>1.1.0</version>
        </dependency>
    </dependencies>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题