Browse Source

Polishing

pull/689/head
Juergen Hoeller 12 years ago
parent
commit
780ea59ff3
  1. 5
      spring-aspects/src/main/java/org/springframework/cache/aspectj/AspectJCachingConfiguration.java
  2. 4
      spring-aspects/src/main/java/org/springframework/scheduling/aspectj/AspectJAsyncConfiguration.java
  3. 5
      spring-aspects/src/main/java/org/springframework/transaction/aspectj/AspectJTransactionManagementConfiguration.java
  4. 6
      spring-context/src/main/java/org/springframework/cache/annotation/ProxyCachingConfiguration.java
  5. 27
      spring-context/src/main/java/org/springframework/cache/config/AnnotationDrivenCacheBeanDefinitionParser.java
  6. 47
      spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigUtils.java
  7. 3
      spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncConfigurationSelector.java
  8. 4
      spring-context/src/main/java/org/springframework/scheduling/annotation/ProxyAsyncConfiguration.java
  9. 85
      spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java
  10. 35
      spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationAttributesReadingVisitor.java
  11. 4
      spring-core/src/main/java/org/springframework/core/type/filter/AbstractClassTestingTypeFilter.java
  12. 4
      spring-core/src/main/java/org/springframework/core/type/filter/AspectJTypeFilter.java
  13. 4
      spring-tx/src/main/java/org/springframework/transaction/config/TransactionManagementConfigUtils.java
  14. 41
      spring-web/src/test/java/org/springframework/web/filter/RequestLoggingFilterTests.java

5
spring-aspects/src/main/java/org/springframework/cache/aspectj/AspectJCachingConfiguration.java vendored

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -35,7 +35,7 @@ import org.springframework.context.annotation.Role;
@Configuration @Configuration
public class AspectJCachingConfiguration extends AbstractCachingConfiguration { public class AspectJCachingConfiguration extends AbstractCachingConfiguration {
@Bean(name=AnnotationConfigUtils.CACHE_ASPECT_BEAN_NAME) @Bean(name = AnnotationConfigUtils.CACHE_ASPECT_BEAN_NAME)
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public AnnotationCacheAspect cacheAspect() { public AnnotationCacheAspect cacheAspect() {
AnnotationCacheAspect cacheAspect = AnnotationCacheAspect.aspectOf(); AnnotationCacheAspect cacheAspect = AnnotationCacheAspect.aspectOf();
@ -47,4 +47,5 @@ public class AspectJCachingConfiguration extends AbstractCachingConfiguration {
} }
return cacheAspect; return cacheAspect;
} }
} }

4
spring-aspects/src/main/java/org/springframework/scheduling/aspectj/AspectJAsyncConfiguration.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -37,7 +37,7 @@ import org.springframework.scheduling.annotation.EnableAsync;
@Configuration @Configuration
public class AspectJAsyncConfiguration extends AbstractAsyncConfiguration { public class AspectJAsyncConfiguration extends AbstractAsyncConfiguration {
@Bean(name=AnnotationConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME) @Bean(name = AnnotationConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME)
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public AnnotationAsyncExecutionAspect asyncAdvisor() { public AnnotationAsyncExecutionAspect asyncAdvisor() {
AnnotationAsyncExecutionAspect asyncAspect = AnnotationAsyncExecutionAspect.aspectOf(); AnnotationAsyncExecutionAspect asyncAspect = AnnotationAsyncExecutionAspect.aspectOf();

5
spring-aspects/src/main/java/org/springframework/transaction/aspectj/AspectJTransactionManagementConfiguration.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -37,7 +37,7 @@ import org.springframework.transaction.config.TransactionManagementConfigUtils;
@Configuration @Configuration
public class AspectJTransactionManagementConfiguration extends AbstractTransactionManagementConfiguration { public class AspectJTransactionManagementConfiguration extends AbstractTransactionManagementConfiguration {
@Bean(name=TransactionManagementConfigUtils.TRANSACTION_ASPECT_BEAN_NAME) @Bean(name = TransactionManagementConfigUtils.TRANSACTION_ASPECT_BEAN_NAME)
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public AnnotationTransactionAspect transactionAspect() { public AnnotationTransactionAspect transactionAspect() {
AnnotationTransactionAspect txAspect = AnnotationTransactionAspect.aspectOf(); AnnotationTransactionAspect txAspect = AnnotationTransactionAspect.aspectOf();
@ -46,4 +46,5 @@ public class AspectJTransactionManagementConfiguration extends AbstractTransacti
} }
return txAspect; return txAspect;
} }
} }

6
spring-context/src/main/java/org/springframework/cache/annotation/ProxyCachingConfiguration.java vendored

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -37,11 +37,11 @@ import org.springframework.context.annotation.Role;
@Configuration @Configuration
public class ProxyCachingConfiguration extends AbstractCachingConfiguration { public class ProxyCachingConfiguration extends AbstractCachingConfiguration {
@Bean(name=AnnotationConfigUtils.CACHE_ADVISOR_BEAN_NAME) @Bean(name = AnnotationConfigUtils.CACHE_ADVISOR_BEAN_NAME)
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public BeanFactoryCacheOperationSourceAdvisor cacheAdvisor() { public BeanFactoryCacheOperationSourceAdvisor cacheAdvisor() {
BeanFactoryCacheOperationSourceAdvisor advisor = BeanFactoryCacheOperationSourceAdvisor advisor =
new BeanFactoryCacheOperationSourceAdvisor(); new BeanFactoryCacheOperationSourceAdvisor();
advisor.setCacheOperationSource(cacheOperationSource()); advisor.setCacheOperationSource(cacheOperationSource());
advisor.setAdvice(cacheInterceptor()); advisor.setAdvice(cacheInterceptor());
advisor.setOrder(this.enableCaching.<Integer>getNumber("order")); advisor.setOrder(this.enableCaching.<Integer>getNumber("order"));

27
spring-context/src/main/java/org/springframework/cache/config/AnnotationDrivenCacheBeanDefinitionParser.java vendored

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2011 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,7 +16,7 @@
package org.springframework.cache.config; package org.springframework.cache.config;
import static org.springframework.context.annotation.AnnotationConfigUtils.*; import org.w3c.dom.Element;
import org.springframework.aop.config.AopNamespaceUtils; import org.springframework.aop.config.AopNamespaceUtils;
import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinition;
@ -26,10 +26,9 @@ import org.springframework.beans.factory.parsing.CompositeComponentDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext; import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.cache.annotation.AnnotationCacheOperationSource;
import org.springframework.cache.interceptor.BeanFactoryCacheOperationSourceAdvisor; import org.springframework.cache.interceptor.BeanFactoryCacheOperationSourceAdvisor;
import org.springframework.cache.interceptor.CacheInterceptor; import org.springframework.cache.interceptor.CacheInterceptor;
import org.w3c.dom.Element; import org.springframework.context.annotation.AnnotationConfigUtils;
/** /**
* {@link org.springframework.beans.factory.xml.BeanDefinitionParser} * {@link org.springframework.beans.factory.xml.BeanDefinitionParser}
@ -74,24 +73,21 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
/** /**
* Registers a * Registers a
* <pre> * <pre class="code">
* <bean id="cacheAspect" class="org.springframework.cache.aspectj.AnnotationCacheAspect" factory-method="aspectOf"> * <bean id="cacheAspect" class="org.springframework.cache.aspectj.AnnotationCacheAspect" factory-method="aspectOf">
* <property name="cacheManager" ref="cacheManager"/> * <property name="cacheManager" ref="cacheManager"/>
* <property name="keyGenerator" ref="keyGenerator"/> * <property name="keyGenerator" ref="keyGenerator"/>
* </bean> * </bean>
*
* </pre> * </pre>
* @param element
* @param parserContext
*/ */
private void registerCacheAspect(Element element, ParserContext parserContext) { private void registerCacheAspect(Element element, ParserContext parserContext) {
if (!parserContext.getRegistry().containsBeanDefinition(CACHE_ASPECT_BEAN_NAME)) { if (!parserContext.getRegistry().containsBeanDefinition(AnnotationConfigUtils.CACHE_ASPECT_BEAN_NAME)) {
RootBeanDefinition def = new RootBeanDefinition(); RootBeanDefinition def = new RootBeanDefinition();
def.setBeanClassName(CACHE_ASPECT_CLASS_NAME); def.setBeanClassName(AnnotationConfigUtils.CACHE_ASPECT_CLASS_NAME);
def.setFactoryMethodName("aspectOf"); def.setFactoryMethodName("aspectOf");
parseCacheManagerProperty(element, def); parseCacheManagerProperty(element, def);
CacheNamespaceHandler.parseKeyGenerator(element, def); CacheNamespaceHandler.parseKeyGenerator(element, def);
parserContext.registerBeanComponent(new BeanComponentDefinition(def, CACHE_ASPECT_BEAN_NAME)); parserContext.registerBeanComponent(new BeanComponentDefinition(def, AnnotationConfigUtils.CACHE_ASPECT_BEAN_NAME));
} }
} }
@ -104,11 +100,11 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
public static void configureAutoProxyCreator(Element element, ParserContext parserContext) { public static void configureAutoProxyCreator(Element element, ParserContext parserContext) {
AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element); AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element);
if (!parserContext.getRegistry().containsBeanDefinition(CACHE_ADVISOR_BEAN_NAME)) { if (!parserContext.getRegistry().containsBeanDefinition(AnnotationConfigUtils.CACHE_ADVISOR_BEAN_NAME)) {
Object eleSource = parserContext.extractSource(element); Object eleSource = parserContext.extractSource(element);
// Create the CacheOperationSource definition. // Create the CacheOperationSource definition.
RootBeanDefinition sourceDef = new RootBeanDefinition(AnnotationCacheOperationSource.class); RootBeanDefinition sourceDef = new RootBeanDefinition("org.springframework.cache.annotation.AnnotationCacheOperationSource");
sourceDef.setSource(eleSource); sourceDef.setSource(eleSource);
sourceDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); sourceDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef); String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef);
@ -131,15 +127,16 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
if (element.hasAttribute("order")) { if (element.hasAttribute("order")) {
advisorDef.getPropertyValues().add("order", element.getAttribute("order")); advisorDef.getPropertyValues().add("order", element.getAttribute("order"));
} }
parserContext.getRegistry().registerBeanDefinition(CACHE_ADVISOR_BEAN_NAME, advisorDef); parserContext.getRegistry().registerBeanDefinition(AnnotationConfigUtils.CACHE_ADVISOR_BEAN_NAME, advisorDef);
CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(),
eleSource); eleSource);
compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName)); compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName));
compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName)); compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName));
compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, CACHE_ADVISOR_BEAN_NAME)); compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, AnnotationConfigUtils.CACHE_ADVISOR_BEAN_NAME));
parserContext.registerComponent(compositeDef); parserContext.registerComponent(compositeDef);
} }
} }
} }
} }

47
spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigUtils.java

@ -30,8 +30,6 @@ import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import static org.springframework.context.annotation.MetadataUtils.*;
/** /**
* Utility class that allows for convenient registration of common * Utility class that allows for convenient registration of common
* {@link org.springframework.beans.factory.config.BeanPostProcessor} and * {@link org.springframework.beans.factory.config.BeanPostProcessor} and
@ -85,70 +83,89 @@ public class AnnotationConfigUtils {
public static final String COMMON_ANNOTATION_PROCESSOR_BEAN_NAME = public static final String COMMON_ANNOTATION_PROCESSOR_BEAN_NAME =
"org.springframework.context.annotation.internalCommonAnnotationProcessor"; "org.springframework.context.annotation.internalCommonAnnotationProcessor";
/**
* The bean name of the internally managed JPA annotation processor.
*/
public static final String PERSISTENCE_ANNOTATION_PROCESSOR_BEAN_NAME =
"org.springframework.context.annotation.internalPersistenceAnnotationProcessor";
private static final String PERSISTENCE_ANNOTATION_PROCESSOR_CLASS_NAME =
"org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor";
/** /**
* The bean name of the internally managed Scheduled annotation processor. * The bean name of the internally managed Scheduled annotation processor.
* <p>ATTENTION:</p> This constant is meant for internal use only. The value is stable
* but don't rely on the presence of this constant declaration; rather copy the value.
*/ */
public static final String SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME = public static final String SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME =
"org.springframework.context.annotation.internalScheduledAnnotationProcessor"; "org.springframework.context.annotation.internalScheduledAnnotationProcessor";
/** /**
* The bean name of the internally managed Async annotation processor. * The bean name of the internally managed Async annotation processor.
* <p>ATTENTION:</p> This constant is meant for internal use only. The value is stable
* but don't rely on the presence of this constant declaration; rather copy the value.
*/ */
public static final String ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME = public static final String ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME =
"org.springframework.context.annotation.internalAsyncAnnotationProcessor"; "org.springframework.context.annotation.internalAsyncAnnotationProcessor";
/** /**
* The bean name of the internally managed AspectJ async execution aspect. * The bean name of the internally managed AspectJ async execution aspect.
* <p>ATTENTION:</p> This constant is meant for internal use only. The value is stable
* but don't rely on the presence of this constant declaration; rather copy the value.
*/ */
public static final String ASYNC_EXECUTION_ASPECT_BEAN_NAME = public static final String ASYNC_EXECUTION_ASPECT_BEAN_NAME =
"org.springframework.scheduling.config.internalAsyncExecutionAspect"; "org.springframework.scheduling.config.internalAsyncExecutionAspect";
/** /**
* The class name of the AspectJ async execution aspect. * The class name of the AspectJ async execution aspect.
* <p>ATTENTION:</p> This constant is meant for internal use only. The value is stable
* but don't rely on the presence of this constant declaration; rather copy the value.
*/ */
public static final String ASYNC_EXECUTION_ASPECT_CLASS_NAME = public static final String ASYNC_EXECUTION_ASPECT_CLASS_NAME =
"org.springframework.scheduling.aspectj.AnnotationAsyncExecutionAspect"; "org.springframework.scheduling.aspectj.AnnotationAsyncExecutionAspect";
/** /**
* The name of the AspectJ async execution aspect @{@code Configuration} class. * The name of the AspectJ async execution aspect @{@code Configuration} class.
* <p>ATTENTION:</p> This constant is meant for internal use only. The value is stable
* but don't rely on the presence of this constant declaration; rather copy the value.
*/ */
public static final String ASYNC_EXECUTION_ASPECT_CONFIGURATION_CLASS_NAME = public static final String ASYNC_EXECUTION_ASPECT_CONFIGURATION_CLASS_NAME =
"org.springframework.scheduling.aspectj.AspectJAsyncConfiguration"; "org.springframework.scheduling.aspectj.AspectJAsyncConfiguration";
/** /**
* The bean name of the internally managed cache advisor. * The bean name of the internally managed cache advisor.
* <p>ATTENTION:</p> This constant is meant for internal use only. The value is stable
* but don't rely on the presence of this constant declaration; rather copy the value.
*/ */
public static final String CACHE_ADVISOR_BEAN_NAME = public static final String CACHE_ADVISOR_BEAN_NAME =
"org.springframework.cache.config.internalCacheAdvisor"; "org.springframework.cache.config.internalCacheAdvisor";
/** /**
* The bean name of the internally managed cache aspect. * The bean name of the internally managed cache aspect.
* <p>ATTENTION:</p> This constant is meant for internal use only. The value is stable
* but don't rely on the presence of this constant declaration; rather copy the value.
*/ */
public static final String CACHE_ASPECT_BEAN_NAME = public static final String CACHE_ASPECT_BEAN_NAME =
"org.springframework.cache.config.internalCacheAspect"; "org.springframework.cache.config.internalCacheAspect";
/** /**
* The class name of the AspectJ caching aspect. * The class name of the AspectJ caching aspect.
* <p>ATTENTION:</p> This constant is meant for internal use only. The value is stable
* but don't rely on the presence of this constant declaration; rather copy the value.
*/ */
public static final String CACHE_ASPECT_CLASS_NAME = public static final String CACHE_ASPECT_CLASS_NAME =
"org.springframework.cache.aspectj.AnnotationCacheAspect"; "org.springframework.cache.aspectj.AnnotationCacheAspect";
/** /**
* The name of the AspectJ caching aspect @{@code Configuration} class. * The name of the AspectJ caching aspect @{@code Configuration} class.
* <p>ATTENTION:</p> This constant is meant for internal use only. The value is stable
* but don't rely on the presence of this constant declaration; rather copy the value.
*/ */
public static final String CACHE_ASPECT_CONFIGURATION_CLASS_NAME = public static final String CACHE_ASPECT_CONFIGURATION_CLASS_NAME =
"org.springframework.cache.aspectj.AspectJCachingConfiguration"; "org.springframework.cache.aspectj.AspectJCachingConfiguration";
/**
* The bean name of the internally managed JPA annotation processor.
*/
public static final String PERSISTENCE_ANNOTATION_PROCESSOR_BEAN_NAME =
"org.springframework.context.annotation.internalPersistenceAnnotationProcessor";
private static final String PERSISTENCE_ANNOTATION_PROCESSOR_CLASS_NAME =
"org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor";
private static final boolean jsr250Present = private static final boolean jsr250Present =
ClassUtils.isPresent("javax.annotation.Resource", AnnotationConfigUtils.class.getClassLoader()); ClassUtils.isPresent("javax.annotation.Resource", AnnotationConfigUtils.class.getClassLoader());
@ -236,14 +253,14 @@ public class AnnotationConfigUtils {
abd.setPrimary(true); abd.setPrimary(true);
} }
if (metadata.isAnnotated(Lazy.class.getName())) { if (metadata.isAnnotated(Lazy.class.getName())) {
abd.setLazyInit(attributesFor(metadata, Lazy.class).getBoolean("value")); abd.setLazyInit(MetadataUtils.attributesFor(metadata, Lazy.class).getBoolean("value"));
} }
if (metadata.isAnnotated(DependsOn.class.getName())) { if (metadata.isAnnotated(DependsOn.class.getName())) {
abd.setDependsOn(attributesFor(metadata, DependsOn.class).getStringArray("value")); abd.setDependsOn(MetadataUtils.attributesFor(metadata, DependsOn.class).getStringArray("value"));
} }
if (abd instanceof AbstractBeanDefinition) { if (abd instanceof AbstractBeanDefinition) {
if (metadata.isAnnotated(Role.class.getName())) { if (metadata.isAnnotated(Role.class.getName())) {
Integer role = attributesFor(metadata, Role.class).getNumber("value"); Integer role = MetadataUtils.attributesFor(metadata, Role.class).getNumber("value");
((AbstractBeanDefinition)abd).setRole(role); ((AbstractBeanDefinition)abd).setRole(role);
} }
} }

3
spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncConfigurationSelector.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2011 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -28,7 +28,6 @@ import org.springframework.context.annotation.AnnotationConfigUtils;
* @since 3.1 * @since 3.1
* @see EnableAsync * @see EnableAsync
* @see ProxyAsyncConfiguration * @see ProxyAsyncConfiguration
* @see AnnotationConfigUtils#ASYNC_EXECUTION_ASPECT_CONFIGURATION_CLASS_NAME
*/ */
public class AsyncConfigurationSelector extends AdviceModeImportSelector<EnableAsync> { public class AsyncConfigurationSelector extends AdviceModeImportSelector<EnableAsync> {

4
spring-context/src/main/java/org/springframework/scheduling/annotation/ProxyAsyncConfiguration.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -38,7 +38,7 @@ import org.springframework.util.Assert;
@Configuration @Configuration
public class ProxyAsyncConfiguration extends AbstractAsyncConfiguration { public class ProxyAsyncConfiguration extends AbstractAsyncConfiguration {
@Bean(name=AnnotationConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME) @Bean(name = AnnotationConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME)
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public AsyncAnnotationBeanPostProcessor asyncAdvisor() { public AsyncAnnotationBeanPostProcessor asyncAdvisor() {
Assert.notNull(this.enableAsync, "@EnableAsync annotation metadata was not injected"); Assert.notNull(this.enableAsync, "@EnableAsync annotation metadata was not injected");

85
spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -54,7 +54,7 @@ import org.springframework.util.StringValueResolver;
* <p>Auto-detects any {@link SchedulingConfigurer} instances in the container, * <p>Auto-detects any {@link SchedulingConfigurer} instances in the container,
* allowing for customization of the scheduler to be used or for fine-grained control * allowing for customization of the scheduler to be used or for fine-grained control
* over task registration (e.g. registration of {@link Trigger} tasks. * over task registration (e.g. registration of {@link Trigger} tasks.
* See @{@link EnableScheduling} Javadoc for complete usage details. * See the @{@link EnableScheduling} javadocs for complete usage details.
* *
* @author Mark Fisher * @author Mark Fisher
* @author Juergen Hoeller * @author Juergen Hoeller
@ -79,6 +79,10 @@ public class ScheduledAnnotationBeanPostProcessor
private final ScheduledTaskRegistrar registrar = new ScheduledTaskRegistrar(); private final ScheduledTaskRegistrar registrar = new ScheduledTaskRegistrar();
public int getOrder() {
return LOWEST_PRECEDENCE;
}
/** /**
* Set the {@link org.springframework.scheduling.TaskScheduler} that will invoke * Set the {@link org.springframework.scheduling.TaskScheduler} that will invoke
* the scheduled methods, or a {@link java.util.concurrent.ScheduledExecutorService} * the scheduled methods, or a {@link java.util.concurrent.ScheduledExecutorService}
@ -96,10 +100,46 @@ public class ScheduledAnnotationBeanPostProcessor
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
} }
public int getOrder() {
return LOWEST_PRECEDENCE; public void onApplicationEvent(ContextRefreshedEvent event) {
if (event.getApplicationContext() != this.applicationContext) {
return;
}
if (this.scheduler != null) {
this.registrar.setScheduler(this.scheduler);
}
Map<String, SchedulingConfigurer> configurers =
this.applicationContext.getBeansOfType(SchedulingConfigurer.class);
for (SchedulingConfigurer configurer : configurers.values()) {
configurer.configureTasks(this.registrar);
}
if (this.registrar.hasTasks() && this.registrar.getScheduler() == null) {
Map<String, ? super Object> schedulers = new HashMap<String, Object>();
schedulers.putAll(this.applicationContext.getBeansOfType(TaskScheduler.class));
schedulers.putAll(this.applicationContext.getBeansOfType(ScheduledExecutorService.class));
if (schedulers.size() == 0) {
// do nothing -> fall back to default scheduler
}
else if (schedulers.size() == 1) {
this.registrar.setScheduler(schedulers.values().iterator().next());
}
else if (schedulers.size() >= 2){
throw new IllegalStateException(
"More than one TaskScheduler and/or ScheduledExecutorService " +
"exist within the context. Remove all but one of the beans; or " +
"implement the SchedulingConfigurer interface and call " +
"ScheduledTaskRegistrar#setScheduler explicitly within the " +
"configureTasks() callback. Found the following beans: " + schedulers.keySet());
}
}
this.registrar.afterPropertiesSet();
} }
public Object postProcessBeforeInitialization(Object bean, String beanName) { public Object postProcessBeforeInitialization(Object bean, String beanName) {
return bean; return bean;
} }
@ -225,44 +265,9 @@ public class ScheduledAnnotationBeanPostProcessor
return bean; return bean;
} }
public void onApplicationEvent(ContextRefreshedEvent event) {
if (event.getApplicationContext() != this.applicationContext) {
return;
}
Map<String, SchedulingConfigurer> configurers =
this.applicationContext.getBeansOfType(SchedulingConfigurer.class);
if (this.scheduler != null) {
this.registrar.setScheduler(this.scheduler);
}
for (SchedulingConfigurer configurer : configurers.values()) {
configurer.configureTasks(this.registrar);
}
if (this.registrar.hasTasks() && this.registrar.getScheduler() == null) {
Map<String, ? super Object> schedulers = new HashMap<String, Object>();
schedulers.putAll(applicationContext.getBeansOfType(TaskScheduler.class));
schedulers.putAll(applicationContext.getBeansOfType(ScheduledExecutorService.class));
if (schedulers.size() == 0) {
// do nothing -> fall back to default scheduler
}
else if (schedulers.size() == 1) {
this.registrar.setScheduler(schedulers.values().iterator().next());
}
else if (schedulers.size() >= 2){
throw new IllegalStateException(
"More than one TaskScheduler and/or ScheduledExecutorService " +
"exist within the context. Remove all but one of the beans; or " +
"implement the SchedulingConfigurer interface and call " +
"ScheduledTaskRegistrar#setScheduler explicitly within the " +
"configureTasks() callback. Found the following beans: " + schedulers.keySet());
}
}
this.registrar.afterPropertiesSet();
}
public void destroy() throws Exception { public void destroy() throws Exception {
if (this.registrar != null) { this.registrar.destroy();
this.registrar.destroy();
}
} }
} }

35
spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationAttributesReadingVisitor.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -45,7 +45,7 @@ import org.springframework.util.ReflectionUtils;
*/ */
abstract class AbstractRecursiveAnnotationVisitor extends AnnotationVisitor { abstract class AbstractRecursiveAnnotationVisitor extends AnnotationVisitor {
protected final Log logger = LogFactory.getLog(this.getClass()); protected final Log logger = LogFactory.getLog(getClass());
protected final AnnotationAttributes attributes; protected final AnnotationAttributes attributes;
@ -87,10 +87,10 @@ abstract class AbstractRecursiveAnnotationVisitor extends AnnotationVisitor {
} }
} }
catch (ClassNotFoundException ex) { catch (ClassNotFoundException ex) {
this.logger.debug("Failed to classload enum type while reading annotation metadata", ex); logger.debug("Failed to classload enum type while reading annotation metadata", ex);
} }
catch (IllegalAccessException ex) { catch (IllegalAccessException ex) {
this.logger.warn("Could not access enum value while reading annotation metadata", ex); logger.warn("Could not access enum value while reading annotation metadata", ex);
} }
return valueToUse; return valueToUse;
} }
@ -123,8 +123,8 @@ final class RecursiveAnnotationArrayVisitor extends AbstractRecursiveAnnotationV
} }
else { else {
Class<?> arrayClass = newValue.getClass(); Class<?> arrayClass = newValue.getClass();
if(Enum.class.isAssignableFrom(arrayClass)) { if (Enum.class.isAssignableFrom(arrayClass)) {
while(arrayClass.getSuperclass() != null && !arrayClass.isEnum()) { while (arrayClass.getSuperclass() != null && !arrayClass.isEnum()) {
arrayClass = arrayClass.getSuperclass(); arrayClass = arrayClass.getSuperclass();
} }
} }
@ -145,8 +145,8 @@ final class RecursiveAnnotationArrayVisitor extends AbstractRecursiveAnnotationV
public void visitEnd() { public void visitEnd() {
if (!this.allNestedAttributes.isEmpty()) { if (!this.allNestedAttributes.isEmpty()) {
this.attributes.put(this.attributeName, this.allNestedAttributes.toArray( this.attributes.put(this.attributeName,
new AnnotationAttributes[this.allNestedAttributes.size()])); this.allNestedAttributes.toArray(new AnnotationAttributes[this.allNestedAttributes.size()]));
} }
} }
} }
@ -161,8 +161,8 @@ class RecursiveAnnotationAttributesVisitor extends AbstractRecursiveAnnotationVi
private final String annotationType; private final String annotationType;
public RecursiveAnnotationAttributesVisitor( public RecursiveAnnotationAttributesVisitor(String annotationType, AnnotationAttributes attributes,
String annotationType, AnnotationAttributes attributes, ClassLoader classLoader) { ClassLoader classLoader) {
super(classLoader, attributes); super(classLoader, attributes);
this.annotationType = annotationType; this.annotationType = annotationType;
} }
@ -173,7 +173,7 @@ class RecursiveAnnotationAttributesVisitor extends AbstractRecursiveAnnotationVi
doVisitEnd(annotationClass); doVisitEnd(annotationClass);
} }
catch (ClassNotFoundException ex) { catch (ClassNotFoundException ex) {
this.logger.debug("Failed to class-load type while reading annotation metadata. " + logger.debug("Failed to class-load type while reading annotation metadata. " +
"This is a non-fatal error, but certain annotation metadata may be unavailable.", ex); "This is a non-fatal error, but certain annotation metadata may be unavailable.", ex);
} }
} }
@ -183,8 +183,9 @@ class RecursiveAnnotationAttributesVisitor extends AbstractRecursiveAnnotationVi
} }
private void registerDefaultValues(Class<?> annotationClass) { private void registerDefaultValues(Class<?> annotationClass) {
// Only do further scanning for public annotations; we'd run into IllegalAccessExceptions // Only do further scanning for public annotations; we'd run into
// otherwise, and don't want to mess with accessibility in a SecurityManager environment. // IllegalAccessExceptions otherwise, and we don't want to mess with
// accessibility in a SecurityManager environment.
if (Modifier.isPublic(annotationClass.getModifiers())) { if (Modifier.isPublic(annotationClass.getModifiers())) {
// Check declared default values of attributes in the annotation type. // Check declared default values of attributes in the annotation type.
Method[] annotationAttributes = annotationClass.getMethods(); Method[] annotationAttributes = annotationClass.getMethods();
@ -193,15 +194,15 @@ class RecursiveAnnotationAttributesVisitor extends AbstractRecursiveAnnotationVi
Object defaultValue = annotationAttribute.getDefaultValue(); Object defaultValue = annotationAttribute.getDefaultValue();
if (defaultValue != null && !this.attributes.containsKey(attributeName)) { if (defaultValue != null && !this.attributes.containsKey(attributeName)) {
if (defaultValue instanceof Annotation) { if (defaultValue instanceof Annotation) {
defaultValue = AnnotationAttributes.fromMap( defaultValue = AnnotationAttributes.fromMap(AnnotationUtils.getAnnotationAttributes(
AnnotationUtils.getAnnotationAttributes((Annotation) defaultValue, false, true)); (Annotation) defaultValue, false, true));
} }
else if (defaultValue instanceof Annotation[]) { else if (defaultValue instanceof Annotation[]) {
Annotation[] realAnnotations = (Annotation[]) defaultValue; Annotation[] realAnnotations = (Annotation[]) defaultValue;
AnnotationAttributes[] mappedAnnotations = new AnnotationAttributes[realAnnotations.length]; AnnotationAttributes[] mappedAnnotations = new AnnotationAttributes[realAnnotations.length];
for (int i = 0; i < realAnnotations.length; i++) { for (int i = 0; i < realAnnotations.length; i++) {
mappedAnnotations[i] = AnnotationAttributes.fromMap( mappedAnnotations[i] = AnnotationAttributes.fromMap(AnnotationUtils.getAnnotationAttributes(
AnnotationUtils.getAnnotationAttributes(realAnnotations[i], false, true)); realAnnotations[i], false, true));
} }
defaultValue = mappedAnnotations; defaultValue = mappedAnnotations;
} }

4
spring-core/src/main/java/org/springframework/core/type/filter/AbstractClassTestingTypeFilter.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,8 +19,8 @@ package org.springframework.core.type.filter;
import java.io.IOException; import java.io.IOException;
import org.springframework.core.type.ClassMetadata; import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReader; import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
/** /**
* Type filter that exposes a * Type filter that exposes a

4
spring-core/src/main/java/org/springframework/core/type/filter/AspectJTypeFilter.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,8 +29,8 @@ import org.aspectj.weaver.patterns.PatternParser;
import org.aspectj.weaver.patterns.SimpleScope; import org.aspectj.weaver.patterns.SimpleScope;
import org.aspectj.weaver.patterns.TypePattern; import org.aspectj.weaver.patterns.TypePattern;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReader; import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
/** /**
* Type filter that uses AspectJ type pattern for matching. * Type filter that uses AspectJ type pattern for matching.

4
spring-tx/src/main/java/org/springframework/transaction/config/TransactionManagementConfigUtils.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,6 +17,8 @@
package org.springframework.transaction.config; package org.springframework.transaction.config;
/** /**
* Configuration constants for internal sharing across subpackages.
*
* @author Chris Beams * @author Chris Beams
* @since 3.1 * @since 3.1
*/ */

41
spring-web/src/test/java/org/springframework/web/filter/RequestLoggingFilterTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,20 +18,21 @@ package org.springframework.web.filter;
import java.io.IOException; import java.io.IOException;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse; import javax.servlet.ServletResponse;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.junit.Test;
import org.junit.Before; import org.junit.Before;
import static org.junit.Assert.*; import org.junit.Test;
import org.springframework.mock.web.test.MockHttpServletRequest; import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse; import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.util.FileCopyUtils; import org.springframework.util.FileCopyUtils;
import static org.junit.Assert.*;
/** /**
* Test for {@link AbstractRequestLoggingFilter} and sub classes. * Test for {@link AbstractRequestLoggingFilter} and sub classes.
* *
@ -41,11 +42,13 @@ public class RequestLoggingFilterTests {
private MyRequestLoggingFilter filter; private MyRequestLoggingFilter filter;
@Before @Before
public void createFilter() throws Exception { public void createFilter() throws Exception {
filter = new MyRequestLoggingFilter(); filter = new MyRequestLoggingFilter();
} }
@Test @Test
public void uri() throws Exception { public void uri() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest("POST", "/hotels"); final MockHttpServletRequest request = new MockHttpServletRequest("POST", "/hotels");
@ -53,17 +56,17 @@ public class RequestLoggingFilterTests {
request.setQueryString("booking=42"); request.setQueryString("booking=42");
FilterChain filterChain = new NoopFilterChain(); FilterChain filterChain = new NoOpFilterChain();
filter.doFilter(request, response, filterChain); filter.doFilter(request, response, filterChain);
assertNotNull(filter.beforeRequestMessage); assertNotNull(filter.beforeRequestMessage);
assertTrue(filter.beforeRequestMessage.indexOf("uri=/hotel") != -1); assertTrue(filter.beforeRequestMessage.contains("uri=/hotel"));
assertFalse(filter.beforeRequestMessage.indexOf("booking=42") != -1); assertFalse(filter.beforeRequestMessage.contains("booking=42"));
assertNotNull(filter.afterRequestMessage); assertNotNull(filter.afterRequestMessage);
assertTrue(filter.afterRequestMessage.indexOf("uri=/hotel") != -1); assertTrue(filter.afterRequestMessage.contains("uri=/hotel"));
assertFalse(filter.afterRequestMessage.indexOf("booking=42") != -1); assertFalse(filter.afterRequestMessage.contains("booking=42"));
} }
@Test @Test
@ -75,15 +78,15 @@ public class RequestLoggingFilterTests {
request.setQueryString("booking=42"); request.setQueryString("booking=42");
FilterChain filterChain = new NoopFilterChain(); FilterChain filterChain = new NoOpFilterChain();
filter.doFilter(request, response, filterChain); filter.doFilter(request, response, filterChain);
assertNotNull(filter.beforeRequestMessage); assertNotNull(filter.beforeRequestMessage);
assertTrue(filter.beforeRequestMessage.indexOf("uri=/hotels?booking=42") != -1); assertTrue(filter.beforeRequestMessage.contains("uri=/hotels?booking=42"));
assertNotNull(filter.afterRequestMessage); assertNotNull(filter.afterRequestMessage);
assertTrue(filter.afterRequestMessage.indexOf("uri=/hotels?booking=42") != -1); assertTrue(filter.afterRequestMessage.contains("uri=/hotels?booking=42"));
} }
@Test @Test
@ -109,7 +112,7 @@ public class RequestLoggingFilterTests {
filter.doFilter(request, response, filterChain); filter.doFilter(request, response, filterChain);
assertNotNull(filter.afterRequestMessage); assertNotNull(filter.afterRequestMessage);
assertTrue(filter.afterRequestMessage.indexOf("Hello World") != -1); assertTrue(filter.afterRequestMessage.contains("Hello World"));
} }
@Test @Test
@ -135,7 +138,7 @@ public class RequestLoggingFilterTests {
filter.doFilter(request, response, filterChain); filter.doFilter(request, response, filterChain);
assertNotNull(filter.afterRequestMessage); assertNotNull(filter.afterRequestMessage);
assertTrue(filter.afterRequestMessage.indexOf(requestBody) != -1); assertTrue(filter.afterRequestMessage.contains(requestBody));
} }
@Test @Test
@ -162,10 +165,11 @@ public class RequestLoggingFilterTests {
filter.doFilter(request, response, filterChain); filter.doFilter(request, response, filterChain);
assertNotNull(filter.afterRequestMessage); assertNotNull(filter.afterRequestMessage);
assertTrue(filter.afterRequestMessage.indexOf("Hel") != -1); assertTrue(filter.afterRequestMessage.contains("Hel"));
assertFalse(filter.afterRequestMessage.indexOf("Hello World") != -1); assertFalse(filter.afterRequestMessage.contains("Hello World"));
} }
private static class MyRequestLoggingFilter extends AbstractRequestLoggingFilter { private static class MyRequestLoggingFilter extends AbstractRequestLoggingFilter {
private String beforeRequestMessage; private String beforeRequestMessage;
@ -183,7 +187,8 @@ public class RequestLoggingFilterTests {
} }
} }
private static class NoopFilterChain implements FilterChain {
private static class NoOpFilterChain implements FilterChain {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {

Loading…
Cancel
Save