Created
April 25, 2014 17:52
-
-
Save dwelch2344/11297828 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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