/** * Create a ClassPathScanningCandidateComponentProvider with the given {@link Environment}. * @param useDefaultFilters whether to register the default filters for the * {@link Component @Component}, {@link Repository @Repository}, * {@link Service @Service}, and {@link Controller @Controller} * stereotype annotations * @param environment the Environment to use * @see #registerDefaultFilters() */ public ClassPathScanningCandidateComponentProvider(boolean useDefaultFilters, Environment environment) { if (useDefaultFilters) { registerDefaultFilters(); } setEnvironment(environment); setResourceLoader(null); }
/** * Create a ClassPathScanningCandidateComponentProvider with the given {@link Environment}. * @param useDefaultFilters whether to register the default filters for the * {@link Component @Component}, {@link Repository @Repository}, * {@link Service @Service}, and {@link Controller @Controller} * stereotype annotations * @param environment the Environment to use * @see #registerDefaultFilters() */ public ClassPathScanningCandidateComponentProvider(boolean useDefaultFilters, Environment environment) { if (useDefaultFilters) { registerDefaultFilters(); } setEnvironment(environment); setResourceLoader(null); }
private ClassPathScanningCandidateComponentProvider createComponentProvider() { ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider( false); componentProvider.setEnvironment(this.applicationContext.getEnvironment()); componentProvider.setResourceLoader(this.applicationContext); for (ServletComponentHandler handler : HANDLERS) { componentProvider.addIncludeFilter(handler.getTypeFilter()); } return componentProvider; }
@Override public void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo pui) { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false); provider.setEnvironment(environment); provider.setResourceLoader(resourceLoader); provider.addIncludeFilter(new AnnotationTypeFilter(Entity.class)); provider.addIncludeFilter(new AnnotationTypeFilter(MappedSuperclass.class)); for (BeanDefinition definition : provider.findCandidateComponents(basePackage)) { LOG.debug("Registering classpath-scanned entity {} in persistence unit info!", definition.getBeanClassName()); if (definition.getBeanClassName() != null) { pui.addManagedClassName(definition.getBeanClassName()); } } for (String location : scanForMappingFileLocations()) { LOG.debug("Registering classpath-scanned entity mapping file {} in persistence unit info!", location); pui.addMappingFileName(location); } }
@Test public void testWithActiveProfile() { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true); ConfigurableEnvironment env = new StandardEnvironment(); env.setActiveProfiles(ProfileAnnotatedComponent.PROFILE_NAME); provider.setEnvironment(env); Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_PROFILE_PACKAGE); assertThat(containsBeanClass(candidates, ProfileAnnotatedComponent.class), is(true)); }
@Test public void testWithInactiveProfile() { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true); ConfigurableEnvironment env = new StandardEnvironment(); env.setActiveProfiles("other"); provider.setEnvironment(env); Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_PROFILE_PACKAGE); assertThat(containsBeanClass(candidates, ProfileAnnotatedComponent.class), is(false)); }
@Override public void setEnvironment(Environment environment) { super.setEnvironment(environment); this.provider.setEnvironment(environment); }
@Override public void setEnvironment(Environment environment) { super.setEnvironment(environment); this.provider.setEnvironment(environment); }
/** * Create a ClassPathScanningCandidateComponentProvider with the given {@link Environment}. * @param useDefaultFilters whether to register the default filters for the * {@link Component @Component}, {@link Repository @Repository}, * {@link Service @Service}, and {@link Controller @Controller} * stereotype annotations * @param environment the Environment to use * @see #registerDefaultFilters() */ public ClassPathScanningCandidateComponentProvider(boolean useDefaultFilters, Environment environment) { if (useDefaultFilters) { registerDefaultFilters(); } setEnvironment(environment); setResourceLoader(null); }
public Set<Class<?>> findTypes(Iterable<String> basePackages) { ClassPathScanningCandidateComponentProvider provider = new InterfaceAwareScanner(considerInterfaces); if (resourceLoader != null) { provider.setResourceLoader(resourceLoader); } if (environment != null) { provider.setEnvironment(environment); } for (Class<? extends Annotation> annotationType : annotationTypess) { provider.addIncludeFilter(new AnnotationTypeFilter(annotationType, true, considerInterfaces)); } Set<Class<?>> types = new HashSet<>(); ResourceLoader loader = resourceLoader; ClassLoader classLoader = loader == null ? null : loader.getClassLoader(); for (String basePackage : basePackages) { for (BeanDefinition definition : provider.findCandidateComponents(basePackage)) { String beanClassName = definition.getBeanClassName(); if (beanClassName == null) { throw new IllegalStateException( String.format("Unable to obtain bean class name from bean definition %s!", definition)); } try { types.add(ClassUtils.forName(beanClassName, classLoader)); } catch (ClassNotFoundException o_O) { throw new IllegalStateException(o_O); } } } return types; }
public void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo pui) { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false); provider.setEnvironment(environment); provider.setResourceLoader(resourceLoader); provider.addIncludeFilter(new AnnotationTypeFilter(Entity.class)); provider.addIncludeFilter(new AnnotationTypeFilter(MappedSuperclass.class)); for (BeanDefinition definition : provider.findCandidateComponents(basePackage)) { LOG.debug("Registering classpath-scanned entity {} in persistence unit info!", definition.getBeanClassName()); if (definition.getBeanClassName() != null) { pui.addManagedClassName(definition.getBeanClassName()); } } for (String location : scanForMappingFileLocations()) { LOG.debug("Registering classpath-scanned entity mapping file {} in persistence unit info!", location); pui.addMappingFileName(location); } }
ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( false); scanner.setEnvironment(this.environment); scanner.setResourceLoader(this.resourceLoader); scanner.addIncludeFilter(new AnnotationTypeFilter(WicketHomePage.class));
ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( false); scanner.setEnvironment(this.environment); scanner.setResourceLoader(this.resourceLoader); scanner.addIncludeFilter(new AnnotationTypeFilter(WicketHomePage.class));