/** @param args */ public static void main(String[] args) { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true); String basePackage = "com/doctor"; Set<BeanDefinition> components = provider.findCandidateComponents(basePackage); for (BeanDefinition component : components) { System.out.printf("Component: %s\n", component.getBeanClassName()); } }
@SuppressWarnings("rawtypes") private List<Class> findClasses(String packageName) throws ClassNotFoundException { List<Class> classes = new ArrayList<Class>(); ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true); // scanner.addIncludeFilter(new // AnnotationTypeFilter(<TYPE_YOUR_ANNOTATION_HERE>.class)); for (BeanDefinition bd : scanner.findCandidateComponents(packageName)) { classes.add(Class.forName(bd.getBeanClassName())); } return classes; }
/* * (non-Javadoc) * @see org.springframework.orm.jpa.persistenceunit.PersistenceUnitPostProcessor#postProcessPersistenceUnitInfo(org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo) */ public void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo pui) { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false); provider.addIncludeFilter(new AnnotationTypeFilter(Entity.class)); provider.addIncludeFilter(new AnnotationTypeFilter(MappedSuperclass.class)); for (BeanDefinition definition : provider.findCandidateComponents(basePackage)) { LOG.debug( "Registering classpath-scanned entity %s in persistence unit info!", definition.getBeanClassName()); pui.addManagedClassName(definition.getBeanClassName()); } for (String location : scanForMappingFileLocations()) { LOG.debug( "Registering classpath-scanned entity mapping file in persistence unit info!", location); pui.addMappingFileName(location); } }
public void resetFilters(boolean useDefaultFilters) { super.resetFilters(useDefaultFilters); }
/** Add an exclude type filter to the <i>front</i> of the exclusion list. */ public void addExcludeFilter(TypeFilter excludeFilter) { super.addExcludeFilter(excludeFilter); }
/** Add an include type filter to the <i>end</i> of the inclusion list. */ public void addIncludeFilter(TypeFilter includeFilter) { super.addIncludeFilter(includeFilter); }