コード例 #1
0
 /** @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());
   }
 }
コード例 #2
0
  @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);
    }
  }
コード例 #4
0
 public void resetFilters(boolean useDefaultFilters) {
   super.resetFilters(useDefaultFilters);
 }
コード例 #5
0
 /** Add an exclude type filter to the <i>front</i> of the exclusion list. */
 public void addExcludeFilter(TypeFilter excludeFilter) {
   super.addExcludeFilter(excludeFilter);
 }
コード例 #6
0
 /** Add an include type filter to the <i>end</i> of the inclusion list. */
 public void addIncludeFilter(TypeFilter includeFilter) {
   super.addIncludeFilter(includeFilter);
 }