use of cn.taketoday.context.loader.ScopeMetadataResolver in project today-framework by TAKETODAY.
the class AnnotationConfigWebApplicationContext method loadBeanDefinitions.
/**
* Register a {@link BeanDefinition} for
* any classes specified by {@link #register(Class...)} and scan any packages
* specified by {@link #scan(String...)}.
* <p>For any values specified by {@link #setConfigLocation(String)} or
* {@link #setConfigLocations(String[])}, attempt first to load each location as a
* class, registering a {@code BeanDefinition} if class loading is successful,
* and if class loading fails (i.e. a {@code ClassNotFoundException} is raised),
* assume the value is a package and attempt to scan it for component classes.
* <p>Enables the default set of annotation configuration post processors, such that
* {@code @Autowired}, {@code @Required}, and associated annotations can be used.
* <p>Configuration class bean definitions are registered with generated bean
* definition names unless the {@code value} attribute is provided to the stereotype
* annotation.
*
* @param beanFactory the bean factory to load bean definitions into
* @see #register(Class...)
* @see #scan(String...)
* @see #setConfigLocation(String)
* @see #setConfigLocations(String[])
* @see AnnotatedBeanDefinitionReader
* @see ClassPathBeanDefinitionScanner
*/
@Override
protected void loadBeanDefinitions(StandardBeanFactory beanFactory) {
AnnotatedBeanDefinitionReader reader = getAnnotatedBeanDefinitionReader(beanFactory);
ClassPathBeanDefinitionScanner scanner = getClassPathBeanDefinitionScanner(beanFactory);
BeanNameGenerator nameGenerator = getBeanNameGenerator();
if (nameGenerator != null) {
reader.setBeanNameGenerator(nameGenerator);
scanner.setBeanNameGenerator(nameGenerator);
beanFactory.registerSingleton(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR, nameGenerator);
}
ScopeMetadataResolver scopeMetadataResolver = getScopeMetadataResolver();
if (scopeMetadataResolver != null) {
reader.setScopeMetadataResolver(scopeMetadataResolver);
scanner.setScopeMetadataResolver(scopeMetadataResolver);
}
if (!componentClasses.isEmpty()) {
if (log.isDebugEnabled()) {
log.debug("Registering component classes: [{}]", StringUtils.collectionToCommaDelimitedString(componentClasses));
}
reader.register(ClassUtils.toClassArray(componentClasses));
}
if (!basePackages.isEmpty()) {
if (log.isDebugEnabled()) {
log.debug("Scanning base packages: [{}]", StringUtils.collectionToCommaDelimitedString(basePackages));
}
scanner.scan(StringUtils.toStringArray(this.basePackages));
}
String[] configLocations = getConfigLocations();
if (configLocations != null) {
for (String configLocation : configLocations) {
try {
Class<?> clazz = ClassUtils.forName(configLocation, getClassLoader());
if (log.isTraceEnabled()) {
log.trace("Registering [{}]", configLocation);
}
reader.register(clazz);
} catch (ClassNotFoundException ex) {
if (log.isTraceEnabled()) {
log.trace("Could not load class for config location [{}] - trying package scan. {}", configLocation, ex.toString());
}
int count = scanner.scan(configLocation);
if (count == 0 && log.isDebugEnabled()) {
log.debug("No component classes found for specified class/package [{}]", configLocation);
}
}
}
}
}
use of cn.taketoday.context.loader.ScopeMetadataResolver in project today-infrastructure by TAKETODAY.
the class AnnotationConfigWebApplicationContext method loadBeanDefinitions.
/**
* Register a {@link BeanDefinition} for
* any classes specified by {@link #register(Class...)} and scan any packages
* specified by {@link #scan(String...)}.
* <p>For any values specified by {@link #setConfigLocation(String)} or
* {@link #setConfigLocations(String[])}, attempt first to load each location as a
* class, registering a {@code BeanDefinition} if class loading is successful,
* and if class loading fails (i.e. a {@code ClassNotFoundException} is raised),
* assume the value is a package and attempt to scan it for component classes.
* <p>Enables the default set of annotation configuration post processors, such that
* {@code @Autowired}, {@code @Required}, and associated annotations can be used.
* <p>Configuration class bean definitions are registered with generated bean
* definition names unless the {@code value} attribute is provided to the stereotype
* annotation.
*
* @param beanFactory the bean factory to load bean definitions into
* @see #register(Class...)
* @see #scan(String...)
* @see #setConfigLocation(String)
* @see #setConfigLocations(String[])
* @see AnnotatedBeanDefinitionReader
* @see ClassPathBeanDefinitionScanner
*/
@Override
protected void loadBeanDefinitions(StandardBeanFactory beanFactory) {
AnnotatedBeanDefinitionReader reader = getAnnotatedBeanDefinitionReader(beanFactory);
ClassPathBeanDefinitionScanner scanner = getClassPathBeanDefinitionScanner(beanFactory);
BeanNameGenerator nameGenerator = getBeanNameGenerator();
if (nameGenerator != null) {
reader.setBeanNameGenerator(nameGenerator);
scanner.setBeanNameGenerator(nameGenerator);
beanFactory.registerSingleton(AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR, nameGenerator);
}
ScopeMetadataResolver scopeMetadataResolver = getScopeMetadataResolver();
if (scopeMetadataResolver != null) {
reader.setScopeMetadataResolver(scopeMetadataResolver);
scanner.setScopeMetadataResolver(scopeMetadataResolver);
}
if (!componentClasses.isEmpty()) {
if (log.isDebugEnabled()) {
log.debug("Registering component classes: [{}]", StringUtils.collectionToCommaDelimitedString(componentClasses));
}
reader.register(ClassUtils.toClassArray(componentClasses));
}
if (!basePackages.isEmpty()) {
if (log.isDebugEnabled()) {
log.debug("Scanning base packages: [{}]", StringUtils.collectionToCommaDelimitedString(basePackages));
}
scanner.scan(StringUtils.toStringArray(this.basePackages));
}
String[] configLocations = getConfigLocations();
if (configLocations != null) {
for (String configLocation : configLocations) {
try {
Class<?> clazz = ClassUtils.forName(configLocation, getClassLoader());
if (log.isTraceEnabled()) {
log.trace("Registering [{}]", configLocation);
}
reader.register(clazz);
} catch (ClassNotFoundException ex) {
if (log.isTraceEnabled()) {
log.trace("Could not load class for config location [{}] - trying package scan. {}", configLocation, ex.toString());
}
int count = scanner.scan(configLocation);
if (count == 0 && log.isDebugEnabled()) {
log.debug("No component classes found for specified class/package [{}]", configLocation);
}
}
}
}
}
Aggregations