1

I have this error since I insert crudrepository in my interface :

public interface UserRepository extends CrudRepository<Utilisateur, Integer>{

    public Utilisateur findUserById(int id);
    
}

here is my entity

@Entity
@Table(name="utilisateur")
public class Utilisateur {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;

@NotEmpty 
@Email
private String Email; 

@NotEmpty  
@JsonIgnore
private String Password;

private String Role;

public Utilisateur() {}


public Utilisateur(String Email, String Password){
    this.Email=Email;
    this.Password=Password;
}

of course i put getters and setters

and my controller :

@RestController
public class UserController {

    @Autowired
    UserRepository userRepository; 
         
       @PostMapping(value = "/User/add")

    public ResponseEntity<Void> ajouterProduit(@Valid @RequestBody 
    Utilisateur user) {
    Utilisateur userAdded =  userRepository.save(user);
    if (userAdded == null)
        return ResponseEntity.noContent().build();
    
    URI location = ServletUriComponentsBuilder
                    .fromCurrentRequest()
                    .path("/{id}")
                    .buildAndExpand(userAdded.getId())
                    .toUri(); 

    return ResponseEntity.created(location).build(); 
 
      }

I follow the course on springboot on openclassrooms and I applied like that except I introduce Crudrepository to my code

here is the description of the error: enter image description here

Ramses Kouam
  • 531
  • 5
  • 14
  • Do you have `@Repository` annotation in your repository class? – Seldo97 Jul 25 '20 at 23:56
  • @Repository annotation is not necessary since he already extends `CrudRepository`. Can you please provide us with more information. How does stack trace look's like when error is thrown. Do you have any repositories manual configuration or everything is configured out of the box. Can you provide us with working example of error ? (Github). It takes long time to search whole course to find issue you hit. – Norbert Dopjera Jul 26 '20 at 00:53
  • @NorbertDopjera is right, nothing has changed – Ramses Kouam Jul 26 '20 at 00:59
  • i add the error description, hpe it will help you – Ramses Kouam Jul 26 '20 at 00:59
  • Does this answer your question? [Spring boot 2.2.0 Spring HateOas startup issue](https://stackoverflow.com/questions/58431876/spring-boot-2-2-0-spring-hateoas-startup-issue) – Norbert Dopjera Jul 26 '20 at 01:42

1 Answers1

0

From your stack trace we can see that spring context doesn't know which bean should be injected when requesting PluginRegistry since i don't know what plugin registry is i cannot elaborate more but relProviderPluginRegistry and entityLinksPluginRegistry are bean candidate's for this injection and spring cannot decide which one to use. I have found out that this issue is known and there are few workaround's for this. Please see following issue:
https://github.com/spring-projects/spring-hateoas/issues/1094

Just note: I don't know how good those lecture's are but you should never expose your repositories directly to API (RestController) especially when you are working with JPA + Hibernate. Repositories functionality should be hidden behind custom API (@Service or @Component classes exposing repositories functionality adding validation's, restricting access etc.). This is usually done because mutable operation on Model class which is used by Hibernate session's might translate into database operation as well. One should create facade where your Model classes used by repositories are mapped into facade Model classes (same functionality but are not under hibernate management - @Table @Entity annotation's are not used here). You will find more for this problem online.

Norbert Dopjera
  • 741
  • 5
  • 18