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);
}
目录
相关文章
解决方案:Missing URI template variable ‘userName‘ for method parameter of type String
解决方案:Missing URI template variable ‘userName‘ for method parameter of type String
|
3月前
Cannot get property 'versionCode' on extra properties extension as it does not exist
Cannot get property 'versionCode' on extra properties extension as it does not exist
128 0
Property ‘Authorization‘ does not exist on type ‘HeadersDefaults‘
Property ‘Authorization‘ does not exist on type ‘HeadersDefaults‘
88 0
|
缓存 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!
105 0
|
6月前
|
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”?
140 1
|
Java 数据库连接 mybatis
mybatis报错:Type handler was null on parameter mapping or property ‘__frch_xxx_0’
mybatis报错:Type handler was null on parameter mapping or property ‘__frch_xxx_0’
2067 0
mybatis报错:Type handler was null on parameter mapping or property ‘__frch_xxx_0’
|
6月前
|
前端开发
【前端】解决: Property 'inline' does not exist on type 'ClassAttributes<HTMLElement> & HTMLAttribut...
【前端】解决: Property 'inline' does not exist on type 'ClassAttributes<HTMLElement> & HTMLAttribut...
145 0
|
6月前
|
JavaScript API
Property ‘proxy‘ does not exist on type ‘ComponentInternalInstance | null‘.ts
Property ‘proxy‘ does not exist on type ‘ComponentInternalInstance | null‘.ts
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
131 0