0

I'm studying spring building an API using spring-boot,mongodb,lombok, mongock... this project.

When putting HATEOAS I had problems, I noticed that it was related the moment I inherit the RepresentationModel<T> class.

Error complete

Looks like the error is here: [org/springframework/boot/autoconfigure/data/mongo/MongoDataConfiguration.class]: Invocation of init method failed; nested exception is java.lang.reflect.InaccessibleObjectException: Unable to make protected

1 Answers1

0

Taking a quick look to the error trace, it seems your repository is not properly injected into the Spring Context. Try adding the following to your Main class:

@EnableMongoRepositories(basePackageClasses = ClientRepository.class)

Your main class should look like this(notice you can specify the package, instead listing the repository classes):

@EnableMongock
@SpringBootApplication
@EnableMongoRepositories(basePackageClasses = {IItemRepository.class, ITrainerRepository.class})
public class PokeApiApplication {

    public static void main(String[] args) {
        SpringApplication.run(PokeApiApplication.class, args);
    }
}
Mongock team
  • 1,188
  • 5
  • 9
  • The problem continued, the repository works fine. The problem only happens when I inherit this RepresentationModel in my models. If remove inherit RepresentationModel of models the api it works normally. – Eduardo Silva 218 Jun 13 '22 at 11:23
  • I even know how to solve it, I would create a model to use with HATEOAS and another to use with mongo and to create an adapter between them. It works, but it would be a technical debt from the start. – Eduardo Silva 218 Jun 13 '22 at 11:31
  • I highly recommend separating your representation model(HATEOAS) from your persistence. The work to map one to another is worthy...regardless the issue you are experimenting now. – Mongock team Jun 14 '22 at 13:50