Sync with 3.1.x
* 3.1.x: (61 commits) Compensate for changes in JDK 7 Introspector Avoid 'type mismatch' errors in ExtendedBeanInfo Polish ExtendedBeanInfo and tests Infer AnnotationAttributes method return types Minor fix in MVC reference doc chapter Hibernate 4.1 etc TypeDescriptor equals implementation accepts annotations in any order "setBasenames" uses varargs now (for programmatic setup; SPR-9106) @ActiveProfiles mechanism works with @ImportResource as well (SPR-8992 polishing clarified Resource's "getFilename" method to consistently return null substituteNamedParameters detects and unwraps SqlParameterValue object Replace spaces with tabs Consider security in ClassUtils#getMostSpecificMethod Adding null check for username being null. Improvements for registering custom SQL exception translators in app c SPR-7680 Adding QueryTimeoutException to the DataAccessException hiera Minor polish in WebMvcConfigurationSupport Detect overridden boolean getters in ExtendedBeanInfo Polish ExtendedBeanInfoTests ...
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.cache.annotation;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@@ -26,6 +25,7 @@ import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.interceptor.KeyGenerator;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ImportAware;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -41,8 +41,7 @@ import org.springframework.util.CollectionUtils;
|
||||
@Configuration
|
||||
public abstract class AbstractCachingConfiguration implements ImportAware {
|
||||
|
||||
/** Parsed annotation metadata for {@code @EnableCaching} on the importing class. */
|
||||
protected Map<String, Object> enableCaching;
|
||||
protected AnnotationAttributes enableCaching;
|
||||
protected CacheManager cacheManager;
|
||||
protected KeyGenerator keyGenerator;
|
||||
|
||||
@@ -52,8 +51,8 @@ public abstract class AbstractCachingConfiguration implements ImportAware {
|
||||
private Collection<CachingConfigurer> cachingConfigurers;
|
||||
|
||||
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
||||
this.enableCaching = importMetadata.getAnnotationAttributes(
|
||||
EnableCaching.class.getName(), false);
|
||||
this.enableCaching = AnnotationAttributes.fromMap(
|
||||
importMetadata.getAnnotationAttributes(EnableCaching.class.getName(), false));
|
||||
Assert.notNull(this.enableCaching,
|
||||
"@EnableCaching is not present on importing class " +
|
||||
importMetadata.getClassName());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -44,7 +44,7 @@ public class ProxyCachingConfiguration extends AbstractCachingConfiguration {
|
||||
new BeanFactoryCacheOperationSourceAdvisor();
|
||||
advisor.setCacheOperationSource(cacheOperationSource());
|
||||
advisor.setAdvice(cacheInterceptor());
|
||||
advisor.setOrder(((Integer)this.enableCaching.get("order")));
|
||||
advisor.setOrder(this.enableCaching.<Integer>getNumber("order"));
|
||||
return advisor;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,10 +16,12 @@
|
||||
|
||||
package org.springframework.context.annotation;
|
||||
|
||||
import static org.springframework.context.annotation.MetadataUtils.attributesFor;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.core.GenericTypeResolver;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -64,26 +66,16 @@ public abstract class AdviceModeImportSelector<A extends Annotation> implements
|
||||
* returns {@code null}
|
||||
*/
|
||||
public final String[] selectImports(AnnotationMetadata importingClassMetadata) {
|
||||
Class<?> annoType = GenericTypeResolver.resolveTypeArgument(getClass(), AdviceModeImportSelector.class);
|
||||
Class<?> annoType = GenericTypeResolver.resolveTypeArgument(this.getClass(), AdviceModeImportSelector.class);
|
||||
|
||||
Map<String, Object> attributes = importingClassMetadata.getAnnotationAttributes(annoType.getName());
|
||||
AnnotationAttributes attributes = attributesFor(importingClassMetadata, annoType);
|
||||
Assert.notNull(attributes, String.format(
|
||||
"@%s is not present on importing class '%s' as expected",
|
||||
annoType.getSimpleName(), importingClassMetadata.getClassName()));
|
||||
|
||||
String modeAttrName = getAdviceModeAttributeName();
|
||||
Assert.hasText(modeAttrName);
|
||||
AdviceMode adviceMode = attributes.getEnum(this.getAdviceModeAttributeName());
|
||||
|
||||
Object adviceMode = attributes.get(modeAttrName);
|
||||
Assert.notNull(adviceMode, String.format(
|
||||
"Advice mode attribute @%s#%s() does not exist",
|
||||
annoType.getSimpleName(), modeAttrName));
|
||||
|
||||
Assert.isInstanceOf(AdviceMode.class, adviceMode, String.format(
|
||||
"Incorrect type for advice mode attribute '@%s#%s()': ",
|
||||
annoType.getSimpleName(), modeAttrName));
|
||||
|
||||
String[] imports = selectImports((AdviceMode) adviceMode);
|
||||
String[] imports = selectImports(adviceMode);
|
||||
Assert.notNull(imports, String.format("Unknown AdviceMode: '%s'", adviceMode));
|
||||
|
||||
return imports;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,6 +24,7 @@ import org.springframework.beans.factory.support.AutowireCandidateQualifier;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.BeanNameGenerator;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.env.EnvironmentCapable;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
@@ -136,8 +137,9 @@ public class AnnotatedBeanDefinitionReader {
|
||||
AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass);
|
||||
AnnotationMetadata metadata = abd.getMetadata();
|
||||
|
||||
if (ProfileHelper.isProfileAnnotationPresent(metadata)) {
|
||||
if (!this.environment.acceptsProfiles(ProfileHelper.getCandidateProfiles(metadata))) {
|
||||
if (metadata.isAnnotated(Profile.class.getName())) {
|
||||
AnnotationAttributes profile = MetadataUtils.attributesFor(metadata, Profile.class);
|
||||
if (!this.environment.acceptsProfiles(profile.getStringArray("value"))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.BeanNameGenerator;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -85,7 +86,7 @@ public class AnnotationBeanNameGenerator implements BeanNameGenerator {
|
||||
Set<String> types = amd.getAnnotationTypes();
|
||||
String beanName = null;
|
||||
for (String type : types) {
|
||||
Map<String, Object> attributes = amd.getAnnotationAttributes(type);
|
||||
AnnotationAttributes attributes = MetadataUtils.attributesFor(amd, type);
|
||||
if (isStereotypeWithNameValue(type, amd.getMetaAnnotationTypes(type), attributes)) {
|
||||
String value = (String) attributes.get("value");
|
||||
if (StringUtils.hasLength(value)) {
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.context.annotation;
|
||||
|
||||
import static org.springframework.context.annotation.MetadataUtils.attributesFor;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -27,6 +29,7 @@ import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
@@ -217,21 +220,20 @@ public class AnnotationConfigUtils {
|
||||
}
|
||||
|
||||
static void processCommonDefinitionAnnotations(AnnotatedBeanDefinition abd) {
|
||||
if (abd.getMetadata().isAnnotated(Primary.class.getName())) {
|
||||
AnnotationMetadata metadata = abd.getMetadata();
|
||||
if (metadata.isAnnotated(Primary.class.getName())) {
|
||||
abd.setPrimary(true);
|
||||
}
|
||||
if (abd.getMetadata().isAnnotated(Lazy.class.getName())) {
|
||||
Boolean value = (Boolean) abd.getMetadata().getAnnotationAttributes(Lazy.class.getName()).get("value");
|
||||
abd.setLazyInit(value);
|
||||
if (metadata.isAnnotated(Lazy.class.getName())) {
|
||||
abd.setLazyInit(attributesFor(metadata, Lazy.class).getBoolean("value"));
|
||||
}
|
||||
if (abd.getMetadata().isAnnotated(DependsOn.class.getName())) {
|
||||
String[] value = (String[]) abd.getMetadata().getAnnotationAttributes(DependsOn.class.getName()).get("value");
|
||||
abd.setDependsOn(value);
|
||||
if (metadata.isAnnotated(DependsOn.class.getName())) {
|
||||
abd.setDependsOn(attributesFor(metadata, DependsOn.class).getStringArray("value"));
|
||||
}
|
||||
if (abd instanceof AbstractBeanDefinition) {
|
||||
if (abd.getMetadata().isAnnotated(Role.class.getName())) {
|
||||
int value = (Integer) abd.getMetadata().getAnnotationAttributes(Role.class.getName()).get("value");
|
||||
((AbstractBeanDefinition)abd).setRole(value);
|
||||
if (metadata.isAnnotated(Role.class.getName())) {
|
||||
int role = attributesFor(metadata, Role.class).getNumber("value");
|
||||
((AbstractBeanDefinition)abd).setRole(role);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,11 +16,13 @@
|
||||
|
||||
package org.springframework.context.annotation;
|
||||
|
||||
import static org.springframework.context.annotation.MetadataUtils.attributesFor;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -75,11 +77,11 @@ public class AnnotationScopeMetadataResolver implements ScopeMetadataResolver {
|
||||
ScopeMetadata metadata = new ScopeMetadata();
|
||||
if (definition instanceof AnnotatedBeanDefinition) {
|
||||
AnnotatedBeanDefinition annDef = (AnnotatedBeanDefinition) definition;
|
||||
Map<String, Object> attributes =
|
||||
annDef.getMetadata().getAnnotationAttributes(this.scopeAnnotationType.getName());
|
||||
AnnotationAttributes attributes =
|
||||
attributesFor(annDef.getMetadata(), this.scopeAnnotationType);
|
||||
if (attributes != null) {
|
||||
metadata.setScopeName((String) attributes.get("value"));
|
||||
ScopedProxyMode proxyMode = (ScopedProxyMode) attributes.get("proxyMode");
|
||||
metadata.setScopeName(attributes.getString("value"));
|
||||
ScopedProxyMode proxyMode = attributes.getEnum("proxyMode");
|
||||
if (proxyMode == null || proxyMode == ScopedProxyMode.DEFAULT) {
|
||||
proxyMode = this.defaultProxyMode;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,10 +16,11 @@
|
||||
|
||||
package org.springframework.context.annotation;
|
||||
|
||||
import java.util.Map;
|
||||
import static org.springframework.context.annotation.MetadataUtils.attributesFor;
|
||||
|
||||
import org.springframework.aop.config.AopConfigUtils;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
|
||||
/**
|
||||
@@ -41,12 +42,11 @@ class AspectJAutoProxyRegistrar implements ImportBeanDefinitionRegistrar {
|
||||
public void registerBeanDefinitions(
|
||||
AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
|
||||
|
||||
Map<String, Object> enableAJAutoProxy =
|
||||
importingClassMetadata.getAnnotationAttributes(EnableAspectJAutoProxy.class.getName());
|
||||
|
||||
AopConfigUtils.registerAspectJAnnotationAutoProxyCreatorIfNecessary(registry);
|
||||
|
||||
if ((Boolean)enableAJAutoProxy.get("proxyTargetClass")) {
|
||||
AnnotationAttributes enableAJAutoProxy =
|
||||
attributesFor(importingClassMetadata, EnableAspectJAutoProxy.class);
|
||||
if (enableAJAutoProxy.getBoolean("proxyTargetClass")) {
|
||||
AopConfigUtils.forceAutoProxyCreatorToUseClassProxying(registry);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.context.annotation;
|
||||
|
||||
import static org.springframework.context.annotation.MetadataUtils.attributesFor;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -23,6 +25,7 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.aop.config.AopConfigUtils;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
|
||||
/**
|
||||
@@ -58,7 +61,7 @@ public class AutoProxyRegistrar implements ImportBeanDefinitionRegistrar {
|
||||
boolean candidateFound = false;
|
||||
Set<String> annoTypes = importingClassMetadata.getAnnotationTypes();
|
||||
for (String annoType : annoTypes) {
|
||||
Map<String, Object> candidate = importingClassMetadata.getAnnotationAttributes(annoType);
|
||||
AnnotationAttributes candidate = attributesFor(importingClassMetadata, annoType);
|
||||
Object mode = candidate.get("mode");
|
||||
Object proxyTargetClass = candidate.get("proxyTargetClass");
|
||||
if (mode != null && proxyTargetClass != null
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,6 +29,7 @@ import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.ResourceLoaderAware;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.env.EnvironmentCapable;
|
||||
@@ -302,10 +303,11 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC
|
||||
for (TypeFilter tf : this.includeFilters) {
|
||||
if (tf.match(metadataReader, this.metadataReaderFactory)) {
|
||||
AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
|
||||
if (!ProfileHelper.isProfileAnnotationPresent(metadata)) {
|
||||
if (!metadata.isAnnotated(Profile.class.getName())) {
|
||||
return true;
|
||||
}
|
||||
return this.environment.acceptsProfiles(ProfileHelper.getCandidateProfiles(metadata));
|
||||
AnnotationAttributes profile = MetadataUtils.attributesFor(metadata, Profile.class);
|
||||
return this.environment.acceptsProfiles(profile.getStringArray("value"));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,20 +19,20 @@ package org.springframework.context.annotation;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.BeanNameGenerator;
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
||||
import org.springframework.core.type.filter.AssignableTypeFilter;
|
||||
import org.springframework.core.type.filter.TypeFilter;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -46,18 +46,23 @@ import org.springframework.util.StringUtils;
|
||||
class ComponentScanAnnotationParser {
|
||||
|
||||
private final ResourceLoader resourceLoader;
|
||||
|
||||
private final Environment environment;
|
||||
|
||||
private final BeanDefinitionRegistry registry;
|
||||
|
||||
public ComponentScanAnnotationParser(ResourceLoader resourceLoader, Environment environment, BeanDefinitionRegistry registry) {
|
||||
|
||||
public ComponentScanAnnotationParser(
|
||||
ResourceLoader resourceLoader, Environment environment, BeanDefinitionRegistry registry) {
|
||||
this.resourceLoader = resourceLoader;
|
||||
this.environment = environment;
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
public Set<BeanDefinitionHolder> parse(Map<String, Object> componentScanAttributes) {
|
||||
|
||||
public Set<BeanDefinitionHolder> parse(AnnotationAttributes componentScan) {
|
||||
ClassPathBeanDefinitionScanner scanner =
|
||||
new ClassPathBeanDefinitionScanner(registry, (Boolean)componentScanAttributes.get("useDefaultFilters"));
|
||||
new ClassPathBeanDefinitionScanner(registry, componentScan.getBoolean("useDefaultFilters"));
|
||||
|
||||
Assert.notNull(this.environment, "Environment must not be null");
|
||||
scanner.setEnvironment(this.environment);
|
||||
@@ -65,46 +70,43 @@ class ComponentScanAnnotationParser {
|
||||
Assert.notNull(this.resourceLoader, "ResourceLoader must not be null");
|
||||
scanner.setResourceLoader(this.resourceLoader);
|
||||
|
||||
scanner.setBeanNameGenerator(BeanUtils.instantiateClass(
|
||||
(Class<?>)componentScanAttributes.get("nameGenerator"), BeanNameGenerator.class));
|
||||
Class<? extends BeanNameGenerator> generatorClass = componentScan.getClass("nameGenerator");
|
||||
scanner.setBeanNameGenerator(BeanUtils.instantiateClass(generatorClass));
|
||||
|
||||
ScopedProxyMode scopedProxyMode = (ScopedProxyMode) componentScanAttributes.get("scopedProxy");
|
||||
ScopedProxyMode scopedProxyMode = componentScan.getEnum("scopedProxy");
|
||||
if (scopedProxyMode != ScopedProxyMode.DEFAULT) {
|
||||
scanner.setScopedProxyMode(scopedProxyMode);
|
||||
} else {
|
||||
scanner.setScopeMetadataResolver(BeanUtils.instantiateClass(
|
||||
(Class<?>)componentScanAttributes.get("scopeResolver"), ScopeMetadataResolver.class));
|
||||
Class<? extends ScopeMetadataResolver> resolverClass = componentScan.getClass("scopeResolver");
|
||||
scanner.setScopeMetadataResolver(BeanUtils.instantiateClass(resolverClass));
|
||||
}
|
||||
|
||||
scanner.setResourcePattern((String)componentScanAttributes.get("resourcePattern"));
|
||||
scanner.setResourcePattern(componentScan.getString("resourcePattern"));
|
||||
|
||||
for (Filter filterAnno : (Filter[])componentScanAttributes.get("includeFilters")) {
|
||||
for (TypeFilter typeFilter : typeFiltersFor(filterAnno)) {
|
||||
for (AnnotationAttributes filter : componentScan.getAnnotationArray("includeFilters")) {
|
||||
for (TypeFilter typeFilter : typeFiltersFor(filter)) {
|
||||
scanner.addIncludeFilter(typeFilter);
|
||||
}
|
||||
}
|
||||
for (Filter filterAnno : (Filter[])componentScanAttributes.get("excludeFilters")) {
|
||||
for (TypeFilter typeFilter : typeFiltersFor(filterAnno)) {
|
||||
for (AnnotationAttributes filter : componentScan.getAnnotationArray("excludeFilters")) {
|
||||
for (TypeFilter typeFilter : typeFiltersFor(filter)) {
|
||||
scanner.addExcludeFilter(typeFilter);
|
||||
}
|
||||
}
|
||||
|
||||
List<String> basePackages = new ArrayList<String>();
|
||||
for (String pkg : (String[])componentScanAttributes.get("value")) {
|
||||
for (String pkg : componentScan.getStringArray("value")) {
|
||||
if (StringUtils.hasText(pkg)) {
|
||||
basePackages.add(pkg);
|
||||
}
|
||||
}
|
||||
for (String pkg : (String[])componentScanAttributes.get("basePackages")) {
|
||||
for (String pkg : componentScan.getStringArray("basePackages")) {
|
||||
if (StringUtils.hasText(pkg)) {
|
||||
basePackages.add(pkg);
|
||||
}
|
||||
}
|
||||
for (Class<?> clazz : (Class<?>[])componentScanAttributes.get("basePackageClasses")) {
|
||||
// TODO: loading user types directly here. implications on load-time
|
||||
// weaving may mean we need to revert to stringified class names in
|
||||
// annotation metadata
|
||||
basePackages.add(clazz.getPackage().getName());
|
||||
for (Class<?> clazz : componentScan.getClassArray("basePackageClasses")) {
|
||||
basePackages.add(ClassUtils.getPackageName(clazz));
|
||||
}
|
||||
|
||||
if (basePackages.isEmpty()) {
|
||||
@@ -114,10 +116,12 @@ class ComponentScanAnnotationParser {
|
||||
return scanner.doScan(basePackages.toArray(new String[]{}));
|
||||
}
|
||||
|
||||
private List<TypeFilter> typeFiltersFor(Filter filterAnno) {
|
||||
private List<TypeFilter> typeFiltersFor(AnnotationAttributes filterAttributes) {
|
||||
List<TypeFilter> typeFilters = new ArrayList<TypeFilter>();
|
||||
for (Class<?> filterClass : (Class<?>[])filterAnno.value()) {
|
||||
switch (filterAnno.type()) {
|
||||
FilterType filterType = filterAttributes.getEnum("type");
|
||||
|
||||
for (Class<?> filterClass : filterAttributes.getClassArray("value")) {
|
||||
switch (filterType) {
|
||||
case ANNOTATION:
|
||||
Assert.isAssignable(Annotation.class, filterClass,
|
||||
"An error occured when processing a @ComponentScan " +
|
||||
@@ -136,7 +140,7 @@ class ComponentScanAnnotationParser {
|
||||
typeFilters.add(BeanUtils.instantiateClass(filterClass, TypeFilter.class));
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("unknown filter type " + filterAnno.type());
|
||||
throw new IllegalArgumentException("unknown filter type " + filterType);
|
||||
}
|
||||
}
|
||||
return typeFilters;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,11 +25,13 @@ import java.util.Set;
|
||||
import org.springframework.beans.factory.parsing.Location;
|
||||
import org.springframework.beans.factory.parsing.Problem;
|
||||
import org.springframework.beans.factory.parsing.ProblemReporter;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReader;
|
||||
import org.springframework.core.io.DescriptiveResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.core.type.StandardAnnotationMetadata;
|
||||
import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
@@ -49,25 +51,73 @@ final class ConfigurationClass {
|
||||
|
||||
private final Resource resource;
|
||||
|
||||
private final Map<String, Class<?>> importedResources = new LinkedHashMap<String, Class<?>>();
|
||||
private final Map<String, Class<? extends BeanDefinitionReader>> importedResources =
|
||||
new LinkedHashMap<String, Class<? extends BeanDefinitionReader>>();
|
||||
|
||||
private final Set<BeanMethod> beanMethods = new LinkedHashSet<BeanMethod>();
|
||||
|
||||
private String beanName;
|
||||
|
||||
private final boolean imported;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new {@link ConfigurationClass} with the given name.
|
||||
* @param metadataReader reader used to parse the underlying {@link Class}
|
||||
* @param beanName must not be {@code null}
|
||||
* @throws IllegalArgumentException if beanName is null (as of Spring 3.1.1)
|
||||
* @see ConfigurationClass#ConfigurationClass(Class, boolean)
|
||||
*/
|
||||
public ConfigurationClass(MetadataReader metadataReader, String beanName) {
|
||||
Assert.hasText(beanName, "bean name must not be null");
|
||||
this.metadata = metadataReader.getAnnotationMetadata();
|
||||
this.resource = metadataReader.getResource();
|
||||
this.beanName = beanName;
|
||||
this.imported = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link ConfigurationClass} representing a class that was imported
|
||||
* using the {@link Import} annotation or automatically processed as a nested
|
||||
* configuration class (if imported is {@code true}).
|
||||
* @param metadataReader reader used to parse the underlying {@link Class}
|
||||
* @param beanName name of the {@code @Configuration} class bean
|
||||
* @since 3.1.1
|
||||
*/
|
||||
public ConfigurationClass(MetadataReader metadataReader, boolean imported) {
|
||||
this.metadata = metadataReader.getAnnotationMetadata();
|
||||
this.resource = metadataReader.getResource();
|
||||
this.imported = imported;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link ConfigurationClass} with the given name.
|
||||
* @param clazz the underlying {@link Class} to represent
|
||||
* @param beanName name of the {@code @Configuration} class bean
|
||||
* @throws IllegalArgumentException if beanName is null (as of Spring 3.1.1)
|
||||
* @see ConfigurationClass#ConfigurationClass(Class, boolean)
|
||||
*/
|
||||
public ConfigurationClass(Class<?> clazz, String beanName) {
|
||||
this.metadata = new StandardAnnotationMetadata(clazz);
|
||||
Assert.hasText(beanName, "bean name must not be null");
|
||||
this.metadata = new StandardAnnotationMetadata(clazz, true);
|
||||
this.resource = new DescriptiveResource(clazz.toString());
|
||||
this.beanName = beanName;
|
||||
this.imported = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link ConfigurationClass} representing a class that was imported
|
||||
* using the {@link Import} annotation or automatically processed as a nested
|
||||
* configuration class (if imported is {@code true}).
|
||||
* @param clazz the underlying {@link Class} to represent
|
||||
* @param beanName name of the {@code @Configuration} class bean
|
||||
* @since 3.1.1
|
||||
*/
|
||||
public ConfigurationClass(Class<?> clazz, boolean imported) {
|
||||
this.metadata = new StandardAnnotationMetadata(clazz, true);
|
||||
this.resource = new DescriptiveResource(clazz.toString());
|
||||
this.imported = imported;
|
||||
}
|
||||
|
||||
public AnnotationMetadata getMetadata() {
|
||||
return this.metadata;
|
||||
@@ -81,6 +131,15 @@ final class ConfigurationClass {
|
||||
return ClassUtils.getShortName(getMetadata().getClassName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this configuration class was registered via @{@link Import} or
|
||||
* automatically registered due to being nested within another configuration class.
|
||||
* @since 3.1.1
|
||||
*/
|
||||
public boolean isImported() {
|
||||
return this.imported;
|
||||
}
|
||||
|
||||
public void setBeanName(String beanName) {
|
||||
this.beanName = beanName;
|
||||
}
|
||||
@@ -97,11 +156,12 @@ final class ConfigurationClass {
|
||||
return this.beanMethods;
|
||||
}
|
||||
|
||||
public void addImportedResource(String importedResource, Class<?> readerClass) {
|
||||
public void addImportedResource(
|
||||
String importedResource, Class<? extends BeanDefinitionReader> readerClass) {
|
||||
this.importedResources.put(importedResource, readerClass);
|
||||
}
|
||||
|
||||
public Map<String, Class<?>> getImportedResources() {
|
||||
public Map<String, Class<? extends BeanDefinitionReader>> getImportedResources() {
|
||||
return this.importedResources;
|
||||
}
|
||||
|
||||
@@ -181,5 +241,4 @@ final class ConfigurationClass {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,6 +27,7 @@ import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
|
||||
import org.springframework.beans.factory.annotation.Autowire;
|
||||
import org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor;
|
||||
@@ -43,6 +44,8 @@ import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.GenericBeanDefinition;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
@@ -51,6 +54,8 @@ import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.springframework.context.annotation.MetadataUtils.*;
|
||||
|
||||
/**
|
||||
* Reads a given fully-populated set of ConfigurationClass instances, registering bean
|
||||
* definitions with the given {@link BeanDefinitionRegistry} based on its contents.
|
||||
@@ -76,7 +81,10 @@ class ConfigurationClassBeanDefinitionReader {
|
||||
|
||||
private final MetadataReaderFactory metadataReaderFactory;
|
||||
|
||||
private ResourceLoader resourceLoader;
|
||||
private final ResourceLoader resourceLoader;
|
||||
|
||||
private final Environment environment;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new {@link ConfigurationClassBeanDefinitionReader} instance that will be used
|
||||
@@ -86,13 +94,14 @@ class ConfigurationClassBeanDefinitionReader {
|
||||
*/
|
||||
public ConfigurationClassBeanDefinitionReader(BeanDefinitionRegistry registry, SourceExtractor sourceExtractor,
|
||||
ProblemReporter problemReporter, MetadataReaderFactory metadataReaderFactory,
|
||||
ResourceLoader resourceLoader) {
|
||||
ResourceLoader resourceLoader, Environment environment) {
|
||||
|
||||
this.registry = registry;
|
||||
this.sourceExtractor = sourceExtractor;
|
||||
this.problemReporter = problemReporter;
|
||||
this.metadataReaderFactory = metadataReaderFactory;
|
||||
this.resourceLoader = resourceLoader;
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
|
||||
@@ -122,32 +131,43 @@ class ConfigurationClassBeanDefinitionReader {
|
||||
* Register the {@link Configuration} class itself as a bean definition.
|
||||
*/
|
||||
private void doLoadBeanDefinitionForConfigurationClassIfNecessary(ConfigurationClass configClass) {
|
||||
if (configClass.getBeanName() != null) {
|
||||
// a bean definition already exists for this configuration class -> nothing to do
|
||||
if (!configClass.isImported()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// no bean definition exists yet -> this must be an imported configuration class (@Import).
|
||||
BeanDefinition configBeanDef = new GenericBeanDefinition();
|
||||
String className = configClass.getMetadata().getClassName();
|
||||
configBeanDef.setBeanClassName(className);
|
||||
MetadataReader reader;
|
||||
try {
|
||||
reader = this.metadataReaderFactory.getMetadataReader(className);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException("Could not create MetadataReader for class " + className);
|
||||
}
|
||||
if (ConfigurationClassUtils.checkConfigurationClassCandidate(configBeanDef, this.metadataReaderFactory)) {
|
||||
String configBeanName = BeanDefinitionReaderUtils.registerWithGeneratedName((AbstractBeanDefinition)configBeanDef, this.registry);
|
||||
Map<String, Object> configAttributes =
|
||||
reader.getAnnotationMetadata().getAnnotationAttributes(Configuration.class.getName());
|
||||
|
||||
// has the 'value' attribute of @Configuration been set?
|
||||
String configBeanName = (String) configAttributes.get("value");
|
||||
if (StringUtils.hasText(configBeanName)) {
|
||||
// yes -> register the configuration class bean with this name
|
||||
this.registry.registerBeanDefinition(configBeanName, configBeanDef);
|
||||
}
|
||||
else {
|
||||
// no -> register the configuration class bean with a generated name
|
||||
configBeanName = BeanDefinitionReaderUtils.registerWithGeneratedName((AbstractBeanDefinition)configBeanDef, this.registry);
|
||||
}
|
||||
configClass.setBeanName(configBeanName);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("Registered bean definition for imported @Configuration class %s", configBeanName));
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
MetadataReader reader = this.metadataReaderFactory.getMetadataReader(className);
|
||||
AnnotationMetadata metadata = reader.getAnnotationMetadata();
|
||||
this.problemReporter.error(
|
||||
new InvalidConfigurationImportProblem(className, reader.getResource(), metadata));
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException("Could not create MetadataReader for class " + className);
|
||||
}
|
||||
AnnotationMetadata metadata = reader.getAnnotationMetadata();
|
||||
this.problemReporter.error(
|
||||
new InvalidConfigurationImportProblem(className, reader.getResource(), metadata));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,15 +196,14 @@ class ConfigurationClassBeanDefinitionReader {
|
||||
beanDef.setAttribute(RequiredAnnotationBeanPostProcessor.SKIP_REQUIRED_CHECK_ATTRIBUTE, Boolean.TRUE);
|
||||
|
||||
// consider role
|
||||
Map<String, Object> roleAttributes = metadata.getAnnotationAttributes(Role.class.getName());
|
||||
if (roleAttributes != null) {
|
||||
int role = (Integer) roleAttributes.get("value");
|
||||
beanDef.setRole(role);
|
||||
AnnotationAttributes role = attributesFor(metadata, Role.class);
|
||||
if (role != null) {
|
||||
beanDef.setRole(role.<Integer>getNumber("value"));
|
||||
}
|
||||
|
||||
// consider name and any aliases
|
||||
Map<String, Object> beanAttributes = metadata.getAnnotationAttributes(Bean.class.getName());
|
||||
List<String> names = new ArrayList<String>(Arrays.asList((String[]) beanAttributes.get("name")));
|
||||
AnnotationAttributes bean = attributesFor(metadata, Bean.class);
|
||||
List<String> names = new ArrayList<String>(Arrays.asList(bean.getStringArray("name")));
|
||||
String beanName = (names.size() > 0 ? names.remove(0) : beanMethod.getMetadata().getMethodName());
|
||||
for (String alias : names) {
|
||||
this.registry.registerAlias(beanName, alias);
|
||||
@@ -211,40 +230,43 @@ class ConfigurationClassBeanDefinitionReader {
|
||||
|
||||
// is this bean to be instantiated lazily?
|
||||
if (metadata.isAnnotated(Lazy.class.getName())) {
|
||||
beanDef.setLazyInit((Boolean) metadata.getAnnotationAttributes(Lazy.class.getName()).get("value"));
|
||||
AnnotationAttributes lazy = attributesFor(metadata, Lazy.class);
|
||||
beanDef.setLazyInit(lazy.getBoolean("value"));
|
||||
}
|
||||
else if (configClass.getMetadata().isAnnotated(Lazy.class.getName())){
|
||||
beanDef.setLazyInit((Boolean) configClass.getMetadata().getAnnotationAttributes(Lazy.class.getName()).get("value"));
|
||||
AnnotationAttributes lazy = attributesFor(configClass.getMetadata(), Lazy.class);
|
||||
beanDef.setLazyInit(lazy.getBoolean("value"));
|
||||
}
|
||||
|
||||
if (metadata.isAnnotated(DependsOn.class.getName())) {
|
||||
String[] dependsOn = (String[]) metadata.getAnnotationAttributes(DependsOn.class.getName()).get("value");
|
||||
if (dependsOn.length > 0) {
|
||||
beanDef.setDependsOn(dependsOn);
|
||||
AnnotationAttributes dependsOn = attributesFor(metadata, DependsOn.class);
|
||||
String[] otherBeans = dependsOn.getStringArray("value");
|
||||
if (otherBeans.length > 0) {
|
||||
beanDef.setDependsOn(otherBeans);
|
||||
}
|
||||
}
|
||||
|
||||
Autowire autowire = (Autowire) beanAttributes.get("autowire");
|
||||
Autowire autowire = bean.getEnum("autowire");
|
||||
if (autowire.isAutowire()) {
|
||||
beanDef.setAutowireMode(autowire.value());
|
||||
}
|
||||
|
||||
String initMethodName = (String) beanAttributes.get("initMethod");
|
||||
String initMethodName = bean.getString("initMethod");
|
||||
if (StringUtils.hasText(initMethodName)) {
|
||||
beanDef.setInitMethodName(initMethodName);
|
||||
}
|
||||
|
||||
String destroyMethodName = (String) beanAttributes.get("destroyMethod");
|
||||
String destroyMethodName = bean.getString("destroyMethod");
|
||||
if (StringUtils.hasText(destroyMethodName)) {
|
||||
beanDef.setDestroyMethodName(destroyMethodName);
|
||||
}
|
||||
|
||||
// consider scoping
|
||||
ScopedProxyMode proxyMode = ScopedProxyMode.NO;
|
||||
Map<String, Object> scopeAttributes = metadata.getAnnotationAttributes(Scope.class.getName());
|
||||
if (scopeAttributes != null) {
|
||||
beanDef.setScope((String) scopeAttributes.get("value"));
|
||||
proxyMode = (ScopedProxyMode) scopeAttributes.get("proxyMode");
|
||||
AnnotationAttributes scope = attributesFor(metadata, Scope.class);
|
||||
if (scope != null) {
|
||||
beanDef.setScope(scope.getString("value"));
|
||||
proxyMode = scope.getEnum("proxyMode");
|
||||
if (proxyMode == ScopedProxyMode.DEFAULT) {
|
||||
proxyMode = ScopedProxyMode.NO;
|
||||
}
|
||||
@@ -266,22 +288,24 @@ class ConfigurationClassBeanDefinitionReader {
|
||||
}
|
||||
|
||||
|
||||
private void loadBeanDefinitionsFromImportedResources(Map<String, Class<?>> importedResources) {
|
||||
private void loadBeanDefinitionsFromImportedResources(
|
||||
Map<String, Class<? extends BeanDefinitionReader>> importedResources) {
|
||||
|
||||
Map<Class<?>, BeanDefinitionReader> readerInstanceCache = new HashMap<Class<?>, BeanDefinitionReader>();
|
||||
for (Map.Entry<String, Class<?>> entry : importedResources.entrySet()) {
|
||||
for (Map.Entry<String, Class<? extends BeanDefinitionReader>> entry : importedResources.entrySet()) {
|
||||
String resource = entry.getKey();
|
||||
Class<?> readerClass = entry.getValue();
|
||||
Class<? extends BeanDefinitionReader> readerClass = entry.getValue();
|
||||
if (!readerInstanceCache.containsKey(readerClass)) {
|
||||
try {
|
||||
// Instantiate the specified BeanDefinitionReader
|
||||
BeanDefinitionReader readerInstance = (BeanDefinitionReader)
|
||||
BeanDefinitionReader readerInstance =
|
||||
readerClass.getConstructor(BeanDefinitionRegistry.class).newInstance(this.registry);
|
||||
|
||||
// Delegate the current ResourceLoader to it if possible
|
||||
if (readerInstance instanceof AbstractBeanDefinitionReader) {
|
||||
((AbstractBeanDefinitionReader)readerInstance).setResourceLoader(this.resourceLoader);
|
||||
AbstractBeanDefinitionReader abdr = ((AbstractBeanDefinitionReader) readerInstance);
|
||||
abdr.setResourceLoader(this.resourceLoader);
|
||||
abdr.setEnvironment(this.environment);
|
||||
}
|
||||
|
||||
readerInstanceCache.put(readerClass, readerInstance);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
@@ -336,6 +360,7 @@ class ConfigurationClassBeanDefinitionReader {
|
||||
* declare at least one {@link Bean @Bean} method.
|
||||
*/
|
||||
private static class InvalidConfigurationImportProblem extends Problem {
|
||||
|
||||
public InvalidConfigurationImportProblem(String className, Resource resource, AnnotationMetadata metadata) {
|
||||
super(String.format("%s was @Import'ed but is not annotated with @Configuration " +
|
||||
"nor does it declare any @Bean methods; it does not implement ImportSelector " +
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.context.annotation;
|
||||
|
||||
import static org.springframework.context.annotation.MetadataUtils.attributesFor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.ArrayList;
|
||||
@@ -34,7 +36,9 @@ import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
import org.springframework.beans.factory.parsing.Location;
|
||||
import org.springframework.beans.factory.parsing.Problem;
|
||||
import org.springframework.beans.factory.parsing.ProblemReporter;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReader;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
@@ -119,8 +123,7 @@ class ConfigurationClassParser {
|
||||
/**
|
||||
* Parse the specified {@link Configuration @Configuration} class.
|
||||
* @param clazz the Class to parse
|
||||
* @param beanName may be null, but if populated represents the bean id
|
||||
* (assumes that this configuration class was configured via XML)
|
||||
* @param beanName must not be null (as of Spring 3.1.1)
|
||||
*/
|
||||
public void parse(Class<?> clazz, String beanName) throws IOException {
|
||||
processConfigurationClass(new ConfigurationClass(clazz, beanName));
|
||||
@@ -128,8 +131,9 @@ class ConfigurationClassParser {
|
||||
|
||||
protected void processConfigurationClass(ConfigurationClass configClass) throws IOException {
|
||||
AnnotationMetadata metadata = configClass.getMetadata();
|
||||
if (this.environment != null && ProfileHelper.isProfileAnnotationPresent(metadata)) {
|
||||
if (!this.environment.acceptsProfiles(ProfileHelper.getCandidateProfiles(metadata))) {
|
||||
if (this.environment != null && metadata.isAnnotated(Profile.class.getName())) {
|
||||
AnnotationAttributes profile = MetadataUtils.attributesFor(metadata, Profile.class);
|
||||
if (!this.environment.acceptsProfiles(profile.getStringArray("value"))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -140,7 +144,7 @@ class ConfigurationClassParser {
|
||||
if (superClassName != null && !Object.class.getName().equals(superClassName)) {
|
||||
if (metadata instanceof StandardAnnotationMetadata) {
|
||||
Class<?> clazz = ((StandardAnnotationMetadata) metadata).getIntrospectedClass();
|
||||
metadata = new StandardAnnotationMetadata(clazz.getSuperclass());
|
||||
metadata = new StandardAnnotationMetadata(clazz.getSuperclass(), true);
|
||||
}
|
||||
else {
|
||||
MetadataReader reader = this.metadataReaderFactory.getMetadataReader(superClassName);
|
||||
@@ -167,16 +171,16 @@ class ConfigurationClassParser {
|
||||
MetadataReader reader = this.metadataReaderFactory.getMetadataReader(memberClassName);
|
||||
AnnotationMetadata memberClassMetadata = reader.getAnnotationMetadata();
|
||||
if (ConfigurationClassUtils.isConfigurationCandidate(memberClassMetadata)) {
|
||||
processConfigurationClass(new ConfigurationClass(reader, null));
|
||||
processConfigurationClass(new ConfigurationClass(reader, true));
|
||||
}
|
||||
}
|
||||
|
||||
// process any @PropertySource annotations
|
||||
Map<String, Object> propertySourceAttributes =
|
||||
metadata.getAnnotationAttributes(org.springframework.context.annotation.PropertySource.class.getName());
|
||||
if (propertySourceAttributes != null) {
|
||||
String name = (String) propertySourceAttributes.get("name");
|
||||
String[] locations = (String[]) propertySourceAttributes.get("value");
|
||||
AnnotationAttributes propertySource =
|
||||
attributesFor(metadata, org.springframework.context.annotation.PropertySource.class);
|
||||
if (propertySource != null) {
|
||||
String name = propertySource.getString("name");
|
||||
String[] locations = propertySource.getStringArray("value");
|
||||
ClassLoader classLoader = this.resourceLoader.getClassLoader();
|
||||
for (String location : locations) {
|
||||
location = this.environment.resolveRequiredPlaceholders(location);
|
||||
@@ -188,34 +192,31 @@ class ConfigurationClassParser {
|
||||
}
|
||||
|
||||
// process any @ComponentScan annotions
|
||||
Map<String, Object> componentScanAttributes = metadata.getAnnotationAttributes(ComponentScan.class.getName());
|
||||
if (componentScanAttributes != null) {
|
||||
AnnotationAttributes componentScan = attributesFor(metadata, ComponentScan.class);
|
||||
if (componentScan != null) {
|
||||
// the config class is annotated with @ComponentScan -> perform the scan immediately
|
||||
Set<BeanDefinitionHolder> scannedBeanDefinitions = this.componentScanParser.parse(componentScanAttributes);
|
||||
Set<BeanDefinitionHolder> scannedBeanDefinitions = this.componentScanParser.parse(componentScan);
|
||||
|
||||
// check the set of scanned definitions for any further config classes and parse recursively if necessary
|
||||
for (BeanDefinitionHolder holder : scannedBeanDefinitions) {
|
||||
if (ConfigurationClassUtils.checkConfigurationClassCandidate(holder.getBeanDefinition(), metadataReaderFactory)) {
|
||||
if (ConfigurationClassUtils.checkConfigurationClassCandidate(holder.getBeanDefinition(), this.metadataReaderFactory)) {
|
||||
this.parse(holder.getBeanDefinition().getBeanClassName(), holder.getBeanName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// process any @Import annotations
|
||||
List<Map<String, Object>> allImportAttribs =
|
||||
List<AnnotationAttributes> imports =
|
||||
findAllAnnotationAttributes(Import.class, metadata.getClassName(), true);
|
||||
for (Map<String, Object> importAttribs : allImportAttribs) {
|
||||
processImport(configClass, (String[]) importAttribs.get("value"), true);
|
||||
for (AnnotationAttributes importAnno : imports) {
|
||||
processImport(configClass, importAnno.getStringArray("value"), true);
|
||||
}
|
||||
|
||||
// process any @ImportResource annotations
|
||||
if (metadata.isAnnotated(ImportResource.class.getName())) {
|
||||
String[] resources = (String[]) metadata.getAnnotationAttributes(ImportResource.class.getName()).get("value");
|
||||
Class<?> readerClass = (Class<?>) metadata.getAnnotationAttributes(ImportResource.class.getName()).get("reader");
|
||||
if (readerClass == null) {
|
||||
throw new IllegalStateException("No reader class associated with imported resources: " +
|
||||
StringUtils.arrayToCommaDelimitedString(resources));
|
||||
}
|
||||
AnnotationAttributes importResource = attributesFor(metadata, ImportResource.class);
|
||||
String[] resources = importResource.getStringArray("value");
|
||||
Class<? extends BeanDefinitionReader> readerClass = importResource.getClass("reader");
|
||||
for (String resource : resources) {
|
||||
configClass.addImportedResource(resource, readerClass);
|
||||
}
|
||||
@@ -239,11 +240,11 @@ class ConfigurationClassParser {
|
||||
* @param annotatedClassName the class to inspect
|
||||
* @param classValuesAsString whether class attributes should be returned as strings
|
||||
*/
|
||||
private List<Map<String, Object>> findAllAnnotationAttributes(
|
||||
private List<AnnotationAttributes> findAllAnnotationAttributes(
|
||||
Class<? extends Annotation> targetAnnotation, String annotatedClassName,
|
||||
boolean classValuesAsString) throws IOException {
|
||||
|
||||
List<Map<String, Object>> allAttribs = new ArrayList<Map<String, Object>>();
|
||||
List<AnnotationAttributes> allAttribs = new ArrayList<AnnotationAttributes>();
|
||||
|
||||
MetadataReader reader = this.metadataReaderFactory.getMetadataReader(annotatedClassName);
|
||||
AnnotationMetadata metadata = reader.getAnnotationMetadata();
|
||||
@@ -253,16 +254,17 @@ class ConfigurationClassParser {
|
||||
if (annotationType.equals(targetAnnotationType)) {
|
||||
continue;
|
||||
}
|
||||
MetadataReader metaReader = this.metadataReaderFactory.getMetadataReader(annotationType);
|
||||
Map<String, Object> targetAttribs =
|
||||
metaReader.getAnnotationMetadata().getAnnotationAttributes(targetAnnotationType, classValuesAsString);
|
||||
AnnotationMetadata metaAnnotations =
|
||||
this.metadataReaderFactory.getMetadataReader(annotationType).getAnnotationMetadata();
|
||||
AnnotationAttributes targetAttribs =
|
||||
AnnotationAttributes.fromMap(metaAnnotations.getAnnotationAttributes(targetAnnotationType, classValuesAsString));
|
||||
if (targetAttribs != null) {
|
||||
allAttribs.add(targetAttribs);
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object> localAttribs =
|
||||
metadata.getAnnotationAttributes(targetAnnotationType, classValuesAsString);
|
||||
AnnotationAttributes localAttribs =
|
||||
AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(targetAnnotationType, classValuesAsString));
|
||||
if (localAttribs != null) {
|
||||
allAttribs.add(localAttribs);
|
||||
}
|
||||
@@ -300,7 +302,7 @@ class ConfigurationClassParser {
|
||||
else {
|
||||
// the candidate class not an ImportSelector or ImportBeanDefinitionRegistrar -> process it as a @Configuration class
|
||||
this.importStack.registerImport(importingClassMetadata.getClassName(), candidate);
|
||||
processConfigurationClass(new ConfigurationClass(reader, null));
|
||||
processConfigurationClass(new ConfigurationClass(reader, true));
|
||||
}
|
||||
}
|
||||
this.importStack.pop();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -199,8 +199,8 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
|
||||
|
||||
private ConfigurationClassBeanDefinitionReader getConfigurationClassBeanDefinitionReader(BeanDefinitionRegistry registry) {
|
||||
if (this.reader == null) {
|
||||
this.reader = new ConfigurationClassBeanDefinitionReader(
|
||||
registry, this.sourceExtractor, this.problemReporter, this.metadataReaderFactory, this.resourceLoader);
|
||||
this.reader = new ConfigurationClassBeanDefinitionReader(registry, this.sourceExtractor,
|
||||
this.problemReporter, this.metadataReaderFactory, this.resourceLoader, this.environment);
|
||||
}
|
||||
return this.reader;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -60,7 +60,8 @@ abstract class ConfigurationClassUtils {
|
||||
// Check already loaded Class if present...
|
||||
// since we possibly can't even load the class file for this Class.
|
||||
if (beanDef instanceof AbstractBeanDefinition && ((AbstractBeanDefinition) beanDef).hasBeanClass()) {
|
||||
metadata = new StandardAnnotationMetadata(((AbstractBeanDefinition) beanDef).getBeanClass());
|
||||
Class<?> beanClass = ((AbstractBeanDefinition) beanDef).getBeanClass();
|
||||
metadata = new StandardAnnotationMetadata(beanClass, true);
|
||||
}
|
||||
else {
|
||||
String className = beanDef.getBeanClassName();
|
||||
|
||||
@@ -18,8 +18,6 @@ package org.springframework.context.annotation;
|
||||
|
||||
import static org.springframework.context.weaving.AspectJWeavingEnabler.ASPECTJ_AOP_XML_RESOURCE;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
@@ -27,6 +25,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.EnableLoadTimeWeaving.AspectJWeaving;
|
||||
import org.springframework.context.weaving.AspectJWeavingEnabler;
|
||||
import org.springframework.context.weaving.DefaultContextLoadTimeWeaver;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.instrument.classloading.LoadTimeWeaver;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -46,7 +45,7 @@ import org.springframework.util.Assert;
|
||||
@Configuration
|
||||
public class LoadTimeWeavingConfiguration implements ImportAware, BeanClassLoaderAware {
|
||||
|
||||
private Map<String, Object> enableLTW;
|
||||
private AnnotationAttributes enableLTW;
|
||||
|
||||
@Autowired(required=false)
|
||||
private LoadTimeWeavingConfigurer ltwConfigurer;
|
||||
@@ -54,7 +53,7 @@ public class LoadTimeWeavingConfiguration implements ImportAware, BeanClassLoade
|
||||
private ClassLoader beanClassLoader;
|
||||
|
||||
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
||||
this.enableLTW = importMetadata.getAnnotationAttributes(EnableLoadTimeWeaving.class.getName(), false);
|
||||
this.enableLTW = MetadataUtils.attributesFor(importMetadata, EnableLoadTimeWeaving.class);
|
||||
Assert.notNull(this.enableLTW,
|
||||
"@EnableLoadTimeWeaving is not present on importing class " +
|
||||
importMetadata.getClassName());
|
||||
@@ -79,7 +78,8 @@ public class LoadTimeWeavingConfiguration implements ImportAware, BeanClassLoade
|
||||
loadTimeWeaver = new DefaultContextLoadTimeWeaver(this.beanClassLoader);
|
||||
}
|
||||
|
||||
switch ((AspectJWeaving) this.enableLTW.get("aspectjWeaving")) {
|
||||
AspectJWeaving aspectJWeaving = this.enableLTW.getEnum("aspectjWeaving");
|
||||
switch (aspectJWeaving) {
|
||||
case DISABLED:
|
||||
// AJ weaving is disabled -> do nothing
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.context.annotation;
|
||||
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.core.type.MethodMetadata;
|
||||
|
||||
/**
|
||||
* Convenience methods adapting {@link AnnotationMetadata} and {@link MethodMetadata}
|
||||
* annotation attribute maps to the {@link AnnotationAttributes} API. As of Spring 3.1.1,
|
||||
* both the reflection- and ASM-based implementations of these SPIs return
|
||||
* {@link AnnotationAttributes} instances anyway, but for backward-compatibility, their
|
||||
* signatures still return Maps. Therefore, for the usual case, these methods perform
|
||||
* little more than a cast from Map to AnnotationAttributes.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @since 3.1.1
|
||||
* @see AnnotationAttributes#fromMap(java.util.Map)
|
||||
*/
|
||||
class MetadataUtils {
|
||||
|
||||
public static AnnotationAttributes attributesFor(AnnotationMetadata metadata, Class<?> annoClass) {
|
||||
return attributesFor(metadata, annoClass.getName());
|
||||
}
|
||||
|
||||
public static AnnotationAttributes attributesFor(AnnotationMetadata metadata, String annoClassName) {
|
||||
return AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(annoClassName, false));
|
||||
}
|
||||
|
||||
public static AnnotationAttributes attributesFor(MethodMetadata metadata, Class<?> targetAnno) {
|
||||
return AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(targetAnno.getName()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.context.annotation;
|
||||
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
|
||||
class ProfileHelper {
|
||||
/**
|
||||
* Return whether the given metadata includes Profile information, whether directly or
|
||||
* through meta-annotation.
|
||||
*/
|
||||
static boolean isProfileAnnotationPresent(AnnotationMetadata metadata) {
|
||||
return metadata.isAnnotated(Profile.class.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the String[] of candidate profiles from {@link Profile#value()}.
|
||||
*/
|
||||
static String[] getCandidateProfiles(AnnotationMetadata metadata) {
|
||||
return (String[])metadata.getAnnotationAttributes(Profile.class.getName()).get("value");
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -135,7 +135,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractMessageSource
|
||||
* @see java.util.ResourceBundle
|
||||
*/
|
||||
public void setBasename(String basename) {
|
||||
setBasenames(new String[] {basename});
|
||||
setBasenames(basename);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,7 +153,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractMessageSource
|
||||
* @see #setBasename
|
||||
* @see java.util.ResourceBundle
|
||||
*/
|
||||
public void setBasenames(String[] basenames) {
|
||||
public void setBasenames(String... basenames) {
|
||||
if (basenames != null) {
|
||||
this.basenames = new String[basenames.length];
|
||||
for (int i = 0; i < basenames.length; i++) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -100,7 +100,7 @@ public class ResourceBundleMessageSource extends AbstractMessageSource implement
|
||||
* @see java.util.ResourceBundle#getBundle(String)
|
||||
*/
|
||||
public void setBasename(String basename) {
|
||||
setBasenames(new String[] {basename});
|
||||
setBasenames(basename);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +119,7 @@ public class ResourceBundleMessageSource extends AbstractMessageSource implement
|
||||
* @see #setBasename
|
||||
* @see java.util.ResourceBundle#getBundle(String)
|
||||
*/
|
||||
public void setBasenames(String[] basenames) {
|
||||
public void setBasenames(String... basenames) {
|
||||
if (basenames != null) {
|
||||
this.basenames = new String[basenames.length];
|
||||
for (int i = 0; i < basenames.length; i++) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,6 +36,7 @@ import org.springframework.util.ClassUtils;
|
||||
* <p>Thanks to Ales Justin and Marius Bogoevici for the initial prototype.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.0
|
||||
*/
|
||||
public class JBossLoadTimeWeaver implements LoadTimeWeaver {
|
||||
@@ -55,23 +56,18 @@ public class JBossLoadTimeWeaver implements LoadTimeWeaver {
|
||||
/**
|
||||
* Create a new instance of the {@link JBossLoadTimeWeaver} class using
|
||||
* the supplied {@link ClassLoader}.
|
||||
* @param classLoader the <code>ClassLoader</code> to delegate to for
|
||||
* weaving (must not be <code>null</code>)
|
||||
* @param classLoader the <code>ClassLoader</code> to delegate to for weaving
|
||||
* (must not be <code>null</code>)
|
||||
*/
|
||||
public JBossLoadTimeWeaver(ClassLoader classLoader) {
|
||||
Assert.notNull(classLoader, "ClassLoader must not be null");
|
||||
String loaderClassName = classLoader.getClass().getName();
|
||||
|
||||
if (loaderClassName.startsWith("org.jboss.classloader")) {
|
||||
// JBoss AS 5 or JBoss AS 6
|
||||
this.adapter = new JBossMCAdapter(classLoader);
|
||||
}
|
||||
else if (loaderClassName.startsWith("org.jboss.modules")) {
|
||||
if (classLoader.getClass().getName().startsWith("org.jboss.modules")) {
|
||||
// JBoss AS 7
|
||||
this.adapter = new JBossModulesAdapter(classLoader);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Unexpected ClassLoader type: " + loaderClassName);
|
||||
// JBoss AS 5 or JBoss AS 6
|
||||
this.adapter = new JBossMCAdapter(classLoader);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,12 +17,12 @@
|
||||
package org.springframework.scheduling.annotation;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ImportAware;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -37,12 +37,13 @@ import org.springframework.util.Assert;
|
||||
@Configuration
|
||||
public abstract class AbstractAsyncConfiguration implements ImportAware {
|
||||
|
||||
protected Map<String, Object> enableAsync;
|
||||
protected AnnotationAttributes enableAsync;
|
||||
protected Executor executor;
|
||||
|
||||
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
||||
enableAsync = importMetadata.getAnnotationAttributes(EnableAsync.class.getName(), false);
|
||||
Assert.notNull(enableAsync,
|
||||
this.enableAsync = AnnotationAttributes.fromMap(
|
||||
importMetadata.getAnnotationAttributes(EnableAsync.class.getName(), false));
|
||||
Assert.notNull(this.enableAsync,
|
||||
"@EnableAsync is not present on importing class " +
|
||||
importMetadata.getClassName());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -42,13 +42,11 @@ public class ProxyAsyncConfiguration extends AbstractAsyncConfiguration {
|
||||
@Bean(name=AnnotationConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME)
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
public AsyncAnnotationBeanPostProcessor asyncAdvisor() {
|
||||
Assert.notNull(enableAsync, "@EnableAsync annotation metadata was not injected");
|
||||
Assert.notNull(this.enableAsync, "@EnableAsync annotation metadata was not injected");
|
||||
|
||||
AsyncAnnotationBeanPostProcessor bpp = new AsyncAnnotationBeanPostProcessor();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends Annotation> customAsyncAnnotation =
|
||||
(Class<? extends Annotation>) enableAsync.get("annotation");
|
||||
Class<? extends Annotation> customAsyncAnnotation = enableAsync.getClass("annotation");
|
||||
if (customAsyncAnnotation != AnnotationUtils.getDefaultValue(EnableAsync.class, "annotation")) {
|
||||
bpp.setAsyncAnnotationType(customAsyncAnnotation);
|
||||
}
|
||||
@@ -57,9 +55,8 @@ public class ProxyAsyncConfiguration extends AbstractAsyncConfiguration {
|
||||
bpp.setExecutor(this.executor);
|
||||
}
|
||||
|
||||
bpp.setProxyTargetClass((Boolean) enableAsync.get("proxyTargetClass"));
|
||||
|
||||
bpp.setOrder(((Integer) enableAsync.get("order")));
|
||||
bpp.setProxyTargetClass(this.enableAsync.getBoolean("proxyTargetClass"));
|
||||
bpp.setOrder(this.enableAsync.<Integer>getNumber("order"));
|
||||
|
||||
return bpp;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,7 +28,7 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
* (ideally on the VM bootstrap classpath).
|
||||
*
|
||||
* <p>For details on the ForkJoinPool API and its use with RecursiveActions, see the
|
||||
* <a href="http://download.java.net/jdk7/docs/api/java/util/concurrent/ForkJoinPool.html">JDK 7 javadoc</a>.
|
||||
* <a href="http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ForkJoinPool.html">JDK 7 javadoc</a>.
|
||||
*
|
||||
* <p><code>jsr166.jar</code>, containing <code>java.util.concurrent</code> updates for Java 6, can be obtained
|
||||
* from the <a href="http://gee.cs.oswego.edu/dl/concurrency-interest/">concurrency interest website</a>.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -120,13 +120,6 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
|
||||
this.errors.addAll(errors.getAllErrors());
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the given error code into message codes.
|
||||
* Calls the MessageCodesResolver with appropriate parameters.
|
||||
* @param errorCode the error code to resolve into message codes
|
||||
* @return the resolved message codes
|
||||
* @see #setMessageCodesResolver
|
||||
*/
|
||||
public String[] resolveMessageCodes(String errorCode) {
|
||||
return getMessageCodesResolver().resolveMessageCodes(errorCode, getObjectName());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -220,6 +220,10 @@ public class BindException extends Exception implements BindingResult {
|
||||
this.bindingResult.addError(error);
|
||||
}
|
||||
|
||||
public String[] resolveMessageCodes(String errorCode) {
|
||||
return this.bindingResult.resolveMessageCodes(errorCode);
|
||||
}
|
||||
|
||||
public String[] resolveMessageCodes(String errorCode, String field) {
|
||||
return this.bindingResult.resolveMessageCodes(errorCode, field);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -112,6 +112,14 @@ public interface BindingResult extends Errors {
|
||||
*/
|
||||
void addError(ObjectError error);
|
||||
|
||||
/**
|
||||
* Resolve the given error code into message codes.
|
||||
* <p>Calls the configured {@link MessageCodesResolver} with appropriate parameters.
|
||||
* @param errorCode the error code to resolve into message codes
|
||||
* @return the resolved message codes
|
||||
*/
|
||||
String[] resolveMessageCodes(String errorCode);
|
||||
|
||||
/**
|
||||
* Resolve the given error code into message codes for the given field.
|
||||
* <p>Calls the configured {@link MessageCodesResolver} with appropriate parameters.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,7 +28,6 @@ import javax.validation.Validation;
|
||||
import javax.validation.Validator;
|
||||
import javax.validation.ValidatorContext;
|
||||
import javax.validation.ValidatorFactory;
|
||||
import javax.validation.spi.ValidationProvider;
|
||||
|
||||
import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator;
|
||||
|
||||
@@ -87,7 +86,7 @@ public class LocalValidatorFactoryBean extends SpringValidatorAdapter
|
||||
* @see javax.validation.Validation#byDefaultProvider()
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void setProviderClass(Class<? extends ValidationProvider> providerClass) {
|
||||
public void setProviderClass(Class providerClass) {
|
||||
this.providerClass = providerClass;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -119,12 +119,11 @@ public class SpringValidatorAdapter implements SmartValidator, javax.validation.
|
||||
// can do custom FieldError registration with invalid value from ConstraintViolation,
|
||||
// as necessary for Hibernate Validator compatibility (non-indexed set path in field)
|
||||
BindingResult bindingResult = (BindingResult) errors;
|
||||
String[] errorCodes = bindingResult.resolveMessageCodes(errorCode, field);
|
||||
String nestedField = bindingResult.getNestedPath() + field;
|
||||
ObjectError error;
|
||||
if ("".equals(nestedField)) {
|
||||
error = new ObjectError(
|
||||
errors.getObjectName(), errorCodes, errorArgs, violation.getMessage());
|
||||
String[] errorCodes = bindingResult.resolveMessageCodes(errorCode);
|
||||
bindingResult.addError(new ObjectError(
|
||||
errors.getObjectName(), errorCodes, errorArgs, violation.getMessage()));
|
||||
}
|
||||
else {
|
||||
Object invalidValue = violation.getInvalidValue();
|
||||
@@ -132,11 +131,11 @@ public class SpringValidatorAdapter implements SmartValidator, javax.validation.
|
||||
// bean constraint with property path: retrieve the actual property value
|
||||
invalidValue = bindingResult.getRawFieldValue(field);
|
||||
}
|
||||
error = new FieldError(
|
||||
String[] errorCodes = bindingResult.resolveMessageCodes(errorCode, field);
|
||||
bindingResult.addError(new FieldError(
|
||||
errors.getObjectName(), nestedField, invalidValue, false,
|
||||
errorCodes, errorArgs, violation.getMessage());
|
||||
errorCodes, errorArgs, violation.getMessage()));
|
||||
}
|
||||
bindingResult.addError(error);
|
||||
}
|
||||
else {
|
||||
// got no BindingResult - can only do standard rejectValue call
|
||||
|
||||
Reference in New Issue
Block a user