Ole Bille
Ole Bille

Reputation: 541

Spring boot starter with own Entity and Repository

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?

Upvotes: 3

Views: 889

Answers (1)

Ole Bille
Ole Bille

Reputation: 541

Ok in my Autoconfiguration class I had

@AutoConfigureAfter({JpaRepositoriesAutoConfiguration.class})

I changed that to

@AutoConfigureBefore({JpaRepositoriesAutoConfiguration.class})

And then it worked.

Upvotes: 1

Related Questions