PropertyReferenceException: No property getAll found for type Users!

简介: Java Spring Boot 2.0连接 MongoDB 4.0时候出错。 抛出来一堆异常信息,最后找到问题根源,解决办法:

Java Spring Boot 2.0连接 MongoDB 4.0时候出错。
抛出来一堆异常信息,最后找到问题根源,解决办法:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'homeController': Unsatisfied dependency expressed through field 'usersRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'usersRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property getAll found for type Users!

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:586) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at  

是Repository定义错误,没有getAll(),实体没有Allsh属性,所以一直报错。
实体类的定义:

@Document(collection = "Users")
public class Users {
 
    private int id;
 
    private String name;
 
    public int getId() {
        return id;
    }
    
    public void setId(int id) {
        this.id = id;
    }
    private String password;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

Repository改成规范的方法名就可以了

public interface UsersRepository extends MongoRepository<Users, Integer> {
    public List<Users> getUserByName(String name);
    public Users getUserByNameAndPassword(String name, String password);
    public Users getUserById(int id);
}
目录
相关文章
|
4月前
|
JavaScript API
required string parameter ‘XXX‘is not present 的几种情况
required string parameter ‘XXX‘is not present 的几种情况
1634 0
解决方案:Missing URI template variable ‘userName‘ for method parameter of type String
解决方案:Missing URI template variable ‘userName‘ for method parameter of type String
|
11月前
Property ‘Authorization‘ does not exist on type ‘HeadersDefaults‘
Property ‘Authorization‘ does not exist on type ‘HeadersDefaults‘
78 0
|
11月前
|
缓存 Java 数据库连接
MybatisPlusException: Your property named “xxx“ cannot find the corresponding database column name!
MybatisPlusException: Your property named “xxx“ cannot find the corresponding database column name!
90 0
|
4月前
|
Java
Error:(15, 13) java: No property named “id” exists in source parameter(s). Did you mean “null”?
Error:(15, 13) java: No property named “id” exists in source parameter(s). Did you mean “null”?
93 1
|
4月前
|
JavaScript API
Property ‘proxy‘ does not exist on type ‘ComponentInternalInstance | null‘.ts
Property ‘proxy‘ does not exist on type ‘ComponentInternalInstance | null‘.ts
|
11月前
|
人工智能 自然语言处理 语音技术
Invalid prop: type check failed for prop “index“. Expected String with value “5“问题解决
Invalid prop: type check failed for prop “index“. Expected String with value “5“问题解决
98 0
Error:(15, 13) java: No property named “id” exists in source parameter(s). Did you mean “null”?
Error:(15, 13) java: No property named “id” exists in source parameter(s). Did you mean “null”?
|
Java
The type XXX cannot be resolved. It is indirectly referenced from required .class files
The type XXX cannot be resolved. It is indirectly referenced from required .class files
116 0
MapStruct - No property named “XXX“ exists in source parameter(s). Did you mean “null“?
MapStruct - No property named “XXX“ exists in source parameter(s). Did you mean “null“?
1294 0