Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.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.beans.factory.BeanCreationException:在电子商务项目中_Java_Spring_Spring Mvc_Spring Boot_Spring Data Jpa - Fatal编程技术网

Java org.springframework.beans.factory.BeanCreationException:在电子商务项目中

Java org.springframework.beans.factory.BeanCreationException:在电子商务项目中,java,spring,spring-mvc,spring-boot,spring-data-jpa,Java,Spring,Spring Mvc,Spring Boot,Spring Data Jpa,我使用Spring boot项目,当我运行时,我得到以下错误: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userSecurityService': Unsatisfied dependency expressed through field 'userRepository'; nested exception is org.springfram

我使用Spring boot项目,当我运行时,我得到以下错误:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userSecurityService': Unsatisfied dependency expressed through field 'userRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Could not create query metamodel for method public abstract Ecommerce.entities.User Ecommerce.repository.UserRepository.findByUsername(java.lang.String)!
我假设最后几行是错误堆栈中重要的部分

Could not create query metamodel for method public abstract Ecommerce.entities.User Ecommerce.repository.UserRepository.findByUsername(java.lang.String)!
我有下面提供的用户存储库

public interface UserRepository extends CrudRepository<User, Long> {

    User findByUsername(String username);

    User findByEmail(String email);
}
还提供了用户实体

@Entity
public class User implements UserDetails {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "userId", nullable = false, updatable = false)
    private Long userId;

    private String userName;

    private String password;

    private String firstName;

    private String lastName;

    @Column(name = "email", nullable = false, updatable = false)
    private String email;

    private String phone;

    private boolean enabled = true;

    @OneToOne(cascade = CascadeType.ALL, mappedBy = "user")
    private ShoppingCart shoppingCart;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private List<UserShipping> userShippingList;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private List<UserPayment> userPaymentList;

    @OneToMany(mappedBy = "user")
    private List<Order> orderList;

    @JsonIgnore
    @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    private Set<UserRole> userRoles = new HashSet<>(); 


    // .............. 
    // more lines of code for overriding the methods 

}

这里的问题是什么以及如何解决它?

显然,findByUsername方法的名称应该与用户实体中的属性匹配。在用户实体类中,我使用

@Entity
public class User implements UserDetails {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "userId", nullable = false, updatable = false)
    private Long userId;

    private String userName;
}

当我从用户名改为用户名后,问题就解决了。我在查阅了其他SOF帖子之后就这么做了,但是,我仍然在寻求更好的解释

在Spring JPA存储库中,自动生成的查找程序遵循如下命名约定

findBy<DataMember><Op> 
可以像,在……之间