spring boot Cannot invoke Repository because Repository is null

public class UserList {

    private  String id;
    private String email;
    private String userType;
    private String rolls;
    private String partner;
    private Integer customersLinked;
    private String position;
    private String status;

    ICustomerRepository customerRepository;

    public UserList (Users user){ = user.getId(); = user.getEmail();
        this.userType = user.getUserType();
        this.rolls = user.getRolls();
        this.partner = user.getPartner();

       List<Customer> customersLinked = customerRepository.findAllByLinkedUsersIn(user.getId());
        this.customersLinked = 0;
        this.position = user.getPosition();
        this.status =user.getStatus();

    //Getter and Setter

This class is used as a list in the frontEnd ,get specific data ,not send all the data

 @RequestMapping(value = "usersLinked/{id}/{type}", method = RequestMethod.GET)
    public Object getUsersLinkedById(@PathVariable("id") String id,@PathVariable("type") Integer type) {
        List<String> users = null;
        switch (type) {
            case 0:
                users = usersRepository.findAll().stream().map(m -> m.getId()).collect(Collectors.toList());
        //Add userList
      List<UserList> userList = new ArrayList<>();
            if(users != null)
                    users.forEach(userId ->
                        Optional<Users> user = this.usersRepository.findById(userId);
                          userList.add(new UserList(user.get()));
        return userList;

As you can see from above I am calling al the data from the user repository and sending it the list

My customer repository

public interface ICustomerRepository extends MongoRepository<Customer, String> {

    Customer findByBusinessInformation_businessName(String businessName);

    List<Customer> findByBusinessInformation_partnerAssigned(String partnerAssigned);

    @Query("{ 'LinkedUsers' : ?0 }")
    Customer findByLinkedUsers(String id);

    List<Customer> findAllByLinkedUsersIn(String id);

In the userList I get the error when I add the logic wityh the customerRepository ,without the repository there everything is working(Want to use the repository to get an array of customer and then get the size() of the array and add it to linkedCustomers). Am I missing sommething


  • You are trying to inject the field customerRepository using Autowired annotation, but your class is not injectable.