3

I would like to create a spring boot starter module which has its own entity and repository. But how can I in the autoconfiguration append an entity to the spring context? The spring boot service using this module will have its own entities so it has to be appended.

I have tried like this.

public class StarterEntityRegistrar implements ImportBeanDefinitionRegistrar {
  @Override
  public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    AutoConfigurationPackages.register(registry, MyEntity.class.getPackageName());
  }

}

And in the autoconfiguration I add this

@Import(StarterEntityRegistrar.class)

When I start my spring boot app depending on this starter module I can see the register method is invoked but still the Entity is not picked up.

How can I do this?

1 Answer 1

1

Ok in my Autoconfiguration class I had

@AutoConfigureAfter({JpaRepositoriesAutoConfiguration.class})

I changed that to

@AutoConfigureBefore({JpaRepositoriesAutoConfiguration.class})

And then it worked.

1
  • 1
    Please, can You post a complete solution? I've same issue.
    – ciro
    Commented Aug 22, 2023 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.