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.

Sign up to request clarification or add additional context in comments.

1 Comment

Please, can You post a complete solution? I've same issue.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.