Skip to content

Instantly share code, notes, and snippets.

@dwelch2344
Created April 25, 2014 17:52
Show Gist options
  • Save dwelch2344/11297828 to your computer and use it in GitHub Desktop.
Save dwelch2344/11297828 to your computer and use it in GitHub Desktop.
@Component
public class Foo extends InstantiationAwareBeanPostProcessorAdapter implements BeanDefinitionRegistryPostProcessor {
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry defRegistry) throws BeansException {
DefaultListableBeanFactory registry = (DefaultListableBeanFactory) defRegistry;
Map<String,JpaRepository> repos = registry.getBeansOfType(JpaRepository.class);
// Repos is always empty :(
Set<Class<?>> entities = new Reflections("com.example").getTypesAnnotatedWith(Entity.class);
for(Class<?> entity : entities){
boolean found = false;
for(JpaRepository repo : repos.values()){
Class<?> repoEntity = ResolvableType.forClass(repo.getClass()).getGeneric(0).resolve();
if( entity.equals(repoEntity) ){
log.info("Match!");
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment