扩展 ReactiveQueryByExampleExecutor 抛出 PropertyReferenceException

Extending ReactiveQueryByExampleExecutor throws PropertyReferenceException

我在尝试将 ReactiveQueryByExampleExecutor 实施到我的应用程序的存储库时遇到问题

堆栈跟踪:

    Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract reactor.core.publisher.Mono org.springframework.data.repository.query.ReactiveQueryByExampleExecutor.exists(org.springframework.data.domain.Example)! No property exists found for type Solution!
        at org.springframework.data.r2dbc.repository.query.PartTreeR2dbcQuery.<init>(PartTreeR2dbcQuery.java:70)
        at org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactory$R2dbcQueryLookupStrategy.resolveQuery(R2dbcRepositoryFactory.java:187)
        at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lookupQuery(QueryExecutorMethodInterceptor.java:99)
        at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lambda$mapMethodsToQuery(QueryExecutorMethodInterceptor.java:92)
        at java.base/java.util.stream.ReferencePipeline.accept(ReferencePipeline.java:195)
        at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
        at java.base/java.util.Collections$UnmodifiableCollection.forEachRemaining(Collections.java:1052)
        at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
        at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
        at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.mapMethodsToQuery(QueryExecutorMethodInterceptor.java:94)
        at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lambda$new[=10=](QueryExecutorMethodInterceptor.java:84)
        at java.base/java.util.Optional.map(Optional.java:265)
        at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.<init>(QueryExecutorMethodInterceptor.java:84)
        at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:332)
        at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet(RepositoryFactoryBeanSupport.java:297)
        at org.springframework.data.util.Lazy.getNullable(Lazy.java:211)
        at org.springframework.data.util.Lazy.get(Lazy.java:95)
        at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:300)
        at org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactoryBean.afterPropertiesSet(R2dbcRepositoryFactoryBean.java:143)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1790)
        ... 70 more
    Caused by: org.springframework.data.mapping.PropertyReferenceException: No property exists found for type Solution!
        at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:94)
        at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:382)
        at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:358)
        at org.springframework.data.mapping.PropertyPath.lambda$from[=10=](PropertyPath.java:311)
        at java.base/java.util.concurrent.ConcurrentMap.computeIfAbsent(ConcurrentMap.java:330)
        at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:293)
        at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:276)
        at org.springframework.data.repository.query.parser.Part.<init>(Part.java:82)
        at org.springframework.data.repository.query.parser.PartTree$OrPart.lambda$new[=10=](PartTree.java:251)
        at java.base/java.util.stream.ReferencePipeline.accept(ReferencePipeline.java:195)
        at java.base/java.util.stream.ReferencePipeline.accept(ReferencePipeline.java:177)
        at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
        at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
        at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:252)
        at org.springframework.data.repository.query.parser.PartTree$Predicate.lambda$new[=10=](PartTree.java:381)
        at java.base/java.util.stream.ReferencePipeline.accept(ReferencePipeline.java:195)
        at java.base/java.util.stream.ReferencePipeline.accept(ReferencePipeline.java:177)
        at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
        at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
        at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:382)
        at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:94)
        at org.springframework.data.r2dbc.repository.query.PartTreeR2dbcQuery.<init>(PartTreeR2dbcQuery.java:66)
        ... 94 more

回购:

    import org.springframework.data.repository.query.ReactiveQueryByExampleExecutor;
    import org.springframework.data.repository.reactive.ReactiveSortingRepository;
    public interface MeetingSolverRepository extends ReactiveSortingRepository<Solution, Long>, ReactiveQueryByExampleExecutor<Solution> {
    }

服务:

    @Slf4j
    @Service
    @RequiredArgsConstructor
    public class MeetingSolverServiceImpl implements MeetingSolverService {
        private final MeetingSolverRepository meetingSolverRepository;
        @Override
        public Flux<Solution> findAll(Solution solution) {
            Example<Solution> example = Example.of(solution);
            return meetingSolverRepository.findAll(example);
        }
    }

对象:

import lombok.Data;
import org.springframework.data.annotation.Id;

@Data
public class Solution {

    @Id
    private Long id;
    private Integer tenant;
    private Long meetingId;
    private Long periodId;
    private Long studentId;
    private Long teacherId;
    private Long roomId;

}

数据库配置:


import dev.miku.r2dbc.mysql.MySqlConnectionConfiguration;
import dev.miku.r2dbc.mysql.MySqlConnectionFactory;
import io.r2dbc.spi.ConnectionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration;
import org.springframework.data.r2dbc.connectionfactory.R2dbcTransactionManager;
import org.springframework.data.r2dbc.core.DatabaseClient;
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;
import org.springframework.lang.NonNull;
import org.springframework.transaction.ReactiveTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.reactive.TransactionalOperator;

@Configuration
@EnableR2dbcRepositories
@EnableTransactionManagement
public class R2DBCConfiguration extends AbstractR2dbcConfiguration {

    @Value("${spring.datasource.host}") private String host;
    @Value("${spring.datasource.port}") private Integer port;
    @Value("${spring.datasource.schema-name}") private String database;
    @Value("${spring.datasource.username}") private String username;
    @Value("${spring.datasource.password}") private String password;

    @Bean
    @NonNull
    @Override
    public ConnectionFactory connectionFactory() {
        return MySqlConnectionFactory.from(
                MySqlConnectionConfiguration.builder()
                        .host(host)
                        .port(port)
                        .user(username)
                        .password(password)
                        .database(database)
                        .build());
    }

    @Bean({"r2dbcDatabaseClient"})
    @Primary
    public DatabaseClient databaseClient() {
        return DatabaseClient.create(connectionFactory());
    }

    @Bean
    public ReactiveTransactionManager reactiveTransactionManager(ConnectionFactory connectionFactory) {
        return new R2dbcTransactionManager(connectionFactory);
    }

    @Bean
    public TransactionalOperator transactionalOperator(ReactiveTransactionManager reactiveTransactionManager) {
        return TransactionalOperator.create(reactiveTransactionManager);
    }
}

看起来它正在检查解决方案对象是否存在 属性 和计数等等。 我假设我的设置中遗漏了什么?

如有任何帮助,我们将不胜感激。谢谢。

我不认为 Spring 数据 R2DBC org.springframework.data.r2dbc.repository.support.SimpleR2dbcRepository 实现了 ReactiveQueryByExampleExecutor

不同于 Spring Data JPA 中实现非反应性 QueryByExampleExecutor

的非反应性对应物 SimpleJpaRepository

使用 ReactiveQueryByExampleExecutor 接口扩展您的存储库接口并期望 Spring 引导自动配置 ReactiveQueryByExampleExecutor 实现将不起作用(从 Spring Data R2DBC 1.0 开始)和 Spring 数据将假定来自 ReactiveQueryByExampleExecutor 的未实现方法是实体 属性 查询,因此例外。

解决方案可能是

a) 根据您的要求实现您自己的 ReactiveQueryByExampleExecutor,

b) 切换到 Spring 数据 Mongo 如果它是一个选项,或者

c) 等待社区实施解决方案。我相信 Github 中有一个未解决的问题。祝你好运!