Error in saving entity by extending reactive repository in SpringBoot with webflux

Viewed 611
  1. Here is my document POJO

    @Document(collection = "users") public class Employee implements Serializable {

    @Id
    private UUID id;
    
    private String firstName;
    
    private String lastName;
    
    private String email;
    
    
    public UUID getId() {
        return id;
    }
    
    public void setId(UUID id) {
        this.id = id;
    }
    
    public String getFirstName() {
        return firstName;
    }
    
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    
    public String getLastName() {
        return lastName;
    }
    
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    
    public String getEmail() {
        return email;
    }
    
    public void setEmail(String email) {
        this.email = email;
    }
    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Employee)) return false;
    
        Employee employee = (Employee) o;
    
        if (!getId().equals(employee.getId())) return false;
        if (getFirstName() != null ? !getFirstName().equals(employee.getFirstName()) : employee.getFirstName() != null)
            return false;
        if (getLastName() != null ? !getLastName().equals(employee.getLastName()) : employee.getLastName() != null)
            return false;
        return getEmail().equals(employee.getEmail());
    }
    
    @Override
    public int hashCode() {
        int result = getId().hashCode();
        result = 31 * result + (getFirstName() != null ? getFirstName().hashCode() : 0);
        result = 31 * result + (getLastName() != null ? getLastName().hashCode() : 0);
        result = 31 * result + getEmail().hashCode();
        return result;
    }
    

    }

  2. Here is my repository interface

    @Repository
    public interface EmployeeRepository extends 
             ReactiveMongoRepository<Employee, UUID> {
    
         }
    

3.Here is my handler

@Component
public class EmployeeHandler {

    @Autowired
    private EmployeeRepository employeeRepository;

    public Mono<ServerResponse> createNewEmployee(ServerRequest request) {
        Mono<Employee> employeeMono = request.bodyToMono(Employee.class);
        Mono<Employee> newEmployee = employeeRepository.save(employeeMono);
        return ServerResponse.ok()
                .contentType(MediaType.APPLICATION_JSON)
                .build(newEmployee);
    }
}

Compile error I am seeing at line "Inferred type 'S' for type parameter 'S' is not within its bound; should extend 'com.kj.webfluxcruddemo.entity.Employee'"

Mono<Employee> newEmployee = employeeRepository.save(employeeMono);
0 Answers
Related