Polishing

This commit is contained in:
Juergen Hoeller 2014-01-05 03:01:44 +01:00
parent a0ccd65d51
commit ee2022e54c
4 changed files with 44 additions and 63 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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.
@ -32,6 +32,7 @@ import org.springframework.scheduling.annotation.EnableAsync;
* @since 3.1
* @see EnableAsync
* @see org.springframework.scheduling.annotation.AsyncConfigurationSelector
* @see org.springframework.scheduling.annotation.ProxyAsyncConfiguration
*/
@Configuration
public class AspectJAsyncConfiguration extends AbstractAsyncConfiguration {

View File

@ -54,7 +54,7 @@ public abstract class AbstractAsyncConfiguration implements ImportAware {
/**
* Collect any {@link AsyncConfigurer} beans through autowiring.
*/
@Autowired(required = false)
@Autowired(required=false)
void setConfigurers(Collection<AsyncConfigurer> configurers) {
if (CollectionUtils.isEmpty(configurers)) {
return;
@ -65,4 +65,5 @@ public abstract class AbstractAsyncConfiguration implements ImportAware {
AsyncConfigurer configurer = configurers.iterator().next();
this.executor = configurer.getAsyncExecutor();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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,21 +42,16 @@ public class ProxyAsyncConfiguration extends AbstractAsyncConfiguration {
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public AsyncAnnotationBeanPostProcessor asyncAdvisor() {
Assert.notNull(this.enableAsync, "@EnableAsync annotation metadata was not injected");
AsyncAnnotationBeanPostProcessor bpp = new AsyncAnnotationBeanPostProcessor();
Class<? extends Annotation> customAsyncAnnotation = enableAsync.getClass("annotation");
if (customAsyncAnnotation != AnnotationUtils.getDefaultValue(EnableAsync.class, "annotation")) {
bpp.setAsyncAnnotationType(customAsyncAnnotation);
}
if (this.executor != null) {
bpp.setExecutor(this.executor);
}
bpp.setProxyTargetClass(this.enableAsync.getBoolean("proxyTargetClass"));
bpp.setOrder(this.enableAsync.<Integer>getNumber("order"));
return bpp;
}

View File

@ -28,6 +28,7 @@ import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.subpackage.NonPublicAnnotatedClass;
import org.springframework.stereotype.Component;
@ -37,6 +38,8 @@ import static org.junit.Assert.*;
import static org.springframework.core.annotation.AnnotationUtils.*;
/**
* Unit tests for {@link AnnotationUtils}.
*
* @author Rod Johnson
* @author Juergen Hoeller
* @author Sam Brannen
@ -97,9 +100,9 @@ public class AnnotationUtilsTests {
// }
@Test
public void findAnnotationPrefersInteracesOverLocalMetaAnnotations() {
public void findAnnotationPrefersInterfacesOverLocalMetaAnnotations() {
Component component = AnnotationUtils.findAnnotation(
ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, Component.class);
ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, Component.class);
// By inspecting ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface, one
// might expect that "meta2" should be found; however, with the current
@ -144,8 +147,7 @@ public class AnnotationUtilsTests {
// inherited class-level annotation; note: @Transactional is inherited
assertEquals(InheritedAnnotationInterface.class,
findAnnotationDeclaringClassForTypes(transactionalCandidateList, InheritedAnnotationInterface.class));
assertNull(findAnnotationDeclaringClassForTypes(transactionalCandidateList,
SubInheritedAnnotationInterface.class));
assertNull(findAnnotationDeclaringClassForTypes(transactionalCandidateList, SubInheritedAnnotationInterface.class));
assertEquals(InheritedAnnotationClass.class,
findAnnotationDeclaringClassForTypes(transactionalCandidateList, InheritedAnnotationClass.class));
assertEquals(InheritedAnnotationClass.class,
@ -301,8 +303,7 @@ public class AnnotationUtilsTests {
}
@Test
public void findAnnotationFromInterfaceWhenSuperDoesNotImplementMethod()
throws Exception {
public void findAnnotationFromInterfaceWhenSuperDoesNotImplementMethod() throws Exception {
Method method = SubOfAbstractImplementsInterfaceWithAnnotatedMethod.class.getMethod("foo");
Order order = findAnnotation(method, Order.class);
assertNotNull(order);
@ -322,13 +323,13 @@ public class AnnotationUtilsTests {
}
@Component(value = "meta1")
@Component(value="meta1")
@Order
@Retention(RetentionPolicy.RUNTIME)
@interface Meta1 {
}
@Component(value = "meta2")
@Component(value="meta2")
@Transactional
@Retention(RetentionPolicy.RUNTIME)
@interface Meta2 {
@ -353,25 +354,20 @@ public class AnnotationUtilsTests {
@Order(27)
public void annotatedOnRoot() {
}
public void overrideToAnnotate() {
}
@Order(27)
public void overrideWithoutNewAnnotation() {
}
public void notAnnotated() {
}
@Override
public void fromInterfaceImplementedByRoot() {
}
}
@ -379,21 +375,23 @@ public class AnnotationUtilsTests {
@Order(25)
public void annotatedOnLeaf() {
}
@Override
@Order(1)
public void overrideToAnnotate() {
}
@Override
public void overrideWithoutNewAnnotation() {
}
}
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@interface Transactional {
}
public static abstract class Foo<T> {
@Order(1)
@ -405,7 +403,6 @@ public class AnnotationUtilsTests {
@Override
@Transactional
public void something(final String arg) {
}
}
@ -474,58 +471,45 @@ public class AnnotationUtilsTests {
}
}
public abstract static class AbstractDoesNotImplementInterfaceWithAnnotatedMethod implements
InterfaceWithAnnotatedMethod {
public abstract static class AbstractDoesNotImplementInterfaceWithAnnotatedMethod
implements InterfaceWithAnnotatedMethod {
}
public static class SubOfAbstractImplementsInterfaceWithAnnotatedMethod extends
AbstractDoesNotImplementInterfaceWithAnnotatedMethod {
public static class SubOfAbstractImplementsInterfaceWithAnnotatedMethod
extends AbstractDoesNotImplementInterfaceWithAnnotatedMethod {
@Override
public void foo() {
}
}
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@interface MyRepeatableContainer {
MyRepeatable[] value();
}
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Repeatable(MyRepeatableContainer.class)
@interface MyRepeatable {
String value();
}
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@MyRepeatable("meta")
@interface MyRepeatableMeta {
}
public static interface InterfaceWithRepeated {
@MyRepeatable("a")
@MyRepeatableContainer({ @MyRepeatable("b"), @MyRepeatable("c") })
@MyRepeatableMeta
void foo();
}
}
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@interface Transactional {
}
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@interface MyRepeatableContainer {
MyRepeatable[] value();
}
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Repeatable(MyRepeatableContainer.class)
@interface MyRepeatable {
String value();
}
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@MyRepeatable("meta")
@interface MyRepeatableMeta {
}