Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 原因:org.springframework.data.mapping.PropertyReferenceException:找不到类型User-Redis的属性findAll_Java_Spring Boot_Redis_Jedis_Spring Data Redis - Fatal编程技术网

Java 原因:org.springframework.data.mapping.PropertyReferenceException:找不到类型User-Redis的属性findAll

Java 原因:org.springframework.data.mapping.PropertyReferenceException:找不到类型User-Redis的属性findAll,java,spring-boot,redis,jedis,spring-data-redis,Java,Spring Boot,Redis,Jedis,Spring Data Redis,我不熟悉Redis并使用Spring Boot+Spring Data Redis示例。在本例中,我使用了querybyexampleredisecutoron repository方法,并使用exampleAPI进行自定义查询 以下是Redis NoSQL数据库中的键 redis 127.0.0.1:6379> KEYS * 1) "country:76c78bcc-bb2a-41b3-a1fc-3dbb3042edd6:idx" 2) "country:76c78bcc-bb2a-

我不熟悉
Redis
并使用
Spring Boot+Spring Data Redis
示例。在本例中,我使用了
querybyexampleredisecutor
on repository方法,并使用
example
API进行自定义查询

以下是Redis NoSQL数据库中的键

redis 127.0.0.1:6379> KEYS *
 1) "country:76c78bcc-bb2a-41b3-a1fc-3dbb3042edd6:idx"
 2) "country:76c78bcc-bb2a-41b3-a1fc-3dbb3042edd6"
 3) "user:lastName:Kerr"
 4) "user"
 5) "user:role.roleName:API"
 6) "country:countryName:India"
 7) "Student:name:John Doe"
 8) "user:8252a4b3-22a1-4e6c-99fc-04fed93a21a5:idx"
 9) "user:8252a4b3-22a1-4e6c-99fc-04fed93a21a5"
10) "user:middleName:Lima"
11) "Student"
12) "user:middleName:Mike"
13) "user:firstName:John"
14) "country:countryCode:+91"
15) "user:role.roleName:ADMIN"
16) "user:lastName:Wixson"
17) "Student:1:idx"
18) "user:46ca0606-38a5-4d0c-8cea-38e2c4fa5bfa:idx"
19) "Student:2:idx"
20) "Student:1"
21) "user:firstName:Matt"
22) "user:46ca0606-38a5-4d0c-8cea-38e2c4fa5bfa"
23) "Student:2"
24) "country"
25) "Student:name:Michael Harford"
26) "country:84fc82f2-1c21-4d3e-9429-f1ee1039ceed:idx"
27) "country:84fc82f2-1c21-4d3e-9429-f1ee1039ceed"
redis 127.0.0.1:6379>
存储库方法-

Example<User> example = Example.of(User.builder().firstName("Mike").build());
long count = userRepository.count();
System.out.println(count);
以下错误供参考-

java.lang.IllegalStateException: Failed to execute CommandLineRunner
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:795)
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:776)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230)
    at com.baeldung.MainAppDemo.main(MainAppDemo.java:31)
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type User!
    at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:94)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:358)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:334)
    at org.springframework.data.mapping.PropertyPath.lambda$from$0(PropertyPath.java:287)
    at java.util.concurrent.ConcurrentMap.computeIfAbsent(Unknown Source)
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:269)
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:252)
    at org.springframework.data.repository.query.parser.Part.<init>(Part.java:81)
    at org.springframework.data.repository.query.parser.PartTree$OrPart.lambda$new$0(PartTree.java:250)
    at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
    at java.util.stream.ReferencePipeline$2$1.accept(Unknown Source)
    at java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)
    at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
    at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
    at java.util.stream.ReferencePipeline.collect(Unknown Source)
    at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:251)
    at org.springframework.data.repository.query.parser.PartTree$Predicate.lambda$new$0(PartTree.java:380)
    at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
    at java.util.stream.ReferencePipeline$2$1.accept(Unknown Source)
    at java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)
    at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source)
    at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
    at java.util.stream.ReferencePipeline.collect(Unknown Source)
    at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:381)
    at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:93)
    at org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.createQuery(KeyValuePartTreeQuery.java:206)
    at org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.prepareQuery(KeyValuePartTreeQuery.java:148)
    at org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.execute(KeyValuePartTreeQuery.java:106)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:602)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:590)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
    at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
    at com.sun.proxy.$Proxy69.findAll(Unknown Source)
    at com.baeldung.MainAppDemo.run(MainAppDemo.java:47)
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:792)
    ... 5 common frames omitted
java.lang.IllegalStateException:无法执行CommandLineRunner
位于org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:795)
位于org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:776)
位于org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
位于org.springframework.boot.SpringApplication.run(SpringApplication.java:1242)
位于org.springframework.boot.SpringApplication.run(SpringApplication.java:1230)
位于com.baeldung.MainAppDemo.main(MainAppDemo.java:31)
原因:org.springframework.data.mapping.PropertyReferenceException:找不到类型User的属性findAll!
位于org.springframework.data.mapping.PropertyPath.(PropertyPath.java:94)
位于org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:358)
位于org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:334)
位于org.springframework.data.mapping.PropertyPath.lambda$from$0(PropertyPath.java:287)
位于java.util.concurrent.ConcurrentMap.computeIfAbsent(未知源)
位于org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:269)
位于org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:252)
位于org.springframework.data.repository.query.parser.Part.(Part.java:81)
位于org.springframework.data.repository.query.parser.PartTree$OrPart.lambda$new$0(PartTree.java:250)
位于java.util.stream.ReferencePipeline$3$1.accept(未知源)
位于java.util.stream.ReferencePipeline$2$1.accept(未知源)
位于java.util.Spliterators$ArraySpliterator.ForEachLeving(未知源)
位于java.util.stream.AbstractPipeline.copyInto(未知源)
位于java.util.stream.AbstractPipeline.wrapAndCopyInto(未知源)
位于java.util.stream.ReduceOps$ReduceOp.evaluateSequential(未知源)
位于java.util.stream.AbstractPipeline.evaluate(未知源)
位于java.util.stream.ReferencePipeline.collect(未知源)
位于org.springframework.data.repository.query.parser.PartTree$OrPart.(PartTree.java:251)
位于org.springframework.data.repository.query.parser.PartTree$Predicate.lambda$new$0(PartTree.java:380)
位于java.util.stream.ReferencePipeline$3$1.accept(未知源)
位于java.util.stream.ReferencePipeline$2$1.accept(未知源)
位于java.util.Spliterators$ArraySpliterator.ForEachLeving(未知源)
位于java.util.stream.AbstractPipeline.copyInto(未知源)
位于java.util.stream.AbstractPipeline.wrapAndCopyInto(未知源)
位于java.util.stream.ReduceOps$ReduceOp.evaluateSequential(未知源)
位于java.util.stream.AbstractPipeline.evaluate(未知源)
位于java.util.stream.ReferencePipeline.collect(未知源)
位于org.springframework.data.repository.query.parser.PartTree$Predicate.(PartTree.java:381)
位于org.springframework.data.repository.query.parser.PartTree(PartTree.java:93)
位于org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.createQuery(KeyValuePartTreeQuery.java:206)
位于org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.prepareQuery(KeyValuePartTreeQuery.java:148)
位于org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.execute(KeyValuePartTreeQuery.java:106)
位于org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:602)
位于org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:590)
位于org.springframework.aop.framework.ReflectiveMethodInvocation.procedue(ReflectiveMethodInvocation.java:185)
位于org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
位于org.springframework.aop.framework.ReflectiveMethodInvocation.procedue(ReflectiveMethodInvocation.java:185)
位于org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
位于org.springframework.aop.framework.ReflectiveMethodInvocation.procedue(ReflectiveMethodInvocation.java:185)
位于org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
位于org.springframework.aop.framework.ReflectiveMethodInvocation.procedue(ReflectiveMethodInvocation.java:185)
位于org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
位于com.sun.proxy.$Proxy69.findAll(未知来源)
运行(MainAppDemo.java:47)
位于org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:792)
... 省略了5个公共框架

您正在构建一个
示例
,但不使用它就放弃了它。您正在调用
userRepository.count()它基本上统计所有记录。您应该使用以
为例的
计数

此方法是您的接口,
UserRepository
也应该在其上扩展的方法。然后你可以简单地做

Example<User> example = Example.of(User.builder().firstName("Mike").build());
long count = userRepository.count(example);
System.out.println(count);
Example Example=Example.of(User.builder().firstName(“Mike”).build());
long count=userRepository.count(示例);
系统输出打印项次(计数);

你应该得到你期望的结果

我也遇到过类似的问题。解决方案是升级SpringDataRedisA
Example<User> example = Example.of(User.builder().firstName("Mike").build());
long count = userRepository.count(example);
System.out.println(count);
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-redis</artifactId>
            <version>2.1.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-commons</artifactId>
            <version>2.1.4.RELEASE</version>
        </dependency>