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?

Ole Bille
  • 469
  • 2
  • 14

1 Answers1

1

Ok in my Autoconfiguration class I had

@AutoConfigureAfter({JpaRepositoriesAutoConfiguration.class})

I changed that to

@AutoConfigureBefore({JpaRepositoriesAutoConfiguration.class})

And then it worked.

Ole Bille
  • 469
  • 2
  • 14