Polishing
This commit is contained in:
parent
a0ccd65d51
commit
ee2022e54c
|
@ -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");
|
* 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.
|
||||||
|
@ -32,6 +32,7 @@ import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
* @see EnableAsync
|
* @see EnableAsync
|
||||||
* @see org.springframework.scheduling.annotation.AsyncConfigurationSelector
|
* @see org.springframework.scheduling.annotation.AsyncConfigurationSelector
|
||||||
|
* @see org.springframework.scheduling.annotation.ProxyAsyncConfiguration
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class AspectJAsyncConfiguration extends AbstractAsyncConfiguration {
|
public class AspectJAsyncConfiguration extends AbstractAsyncConfiguration {
|
||||||
|
|
|
@ -54,7 +54,7 @@ public abstract class AbstractAsyncConfiguration implements ImportAware {
|
||||||
/**
|
/**
|
||||||
* Collect any {@link AsyncConfigurer} beans through autowiring.
|
* Collect any {@link AsyncConfigurer} beans through autowiring.
|
||||||
*/
|
*/
|
||||||
@Autowired(required = false)
|
@Autowired(required=false)
|
||||||
void setConfigurers(Collection<AsyncConfigurer> configurers) {
|
void setConfigurers(Collection<AsyncConfigurer> configurers) {
|
||||||
if (CollectionUtils.isEmpty(configurers)) {
|
if (CollectionUtils.isEmpty(configurers)) {
|
||||||
return;
|
return;
|
||||||
|
@ -65,4 +65,5 @@ public abstract class AbstractAsyncConfiguration implements ImportAware {
|
||||||
AsyncConfigurer configurer = configurers.iterator().next();
|
AsyncConfigurer configurer = configurers.iterator().next();
|
||||||
this.executor = configurer.getAsyncExecutor();
|
this.executor = configurer.getAsyncExecutor();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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");
|
* 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.
|
||||||
|
@ -42,21 +42,16 @@ public class ProxyAsyncConfiguration extends AbstractAsyncConfiguration {
|
||||||
@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");
|
||||||
|
|
||||||
AsyncAnnotationBeanPostProcessor bpp = new AsyncAnnotationBeanPostProcessor();
|
AsyncAnnotationBeanPostProcessor bpp = new AsyncAnnotationBeanPostProcessor();
|
||||||
|
|
||||||
Class<? extends Annotation> customAsyncAnnotation = enableAsync.getClass("annotation");
|
Class<? extends Annotation> customAsyncAnnotation = enableAsync.getClass("annotation");
|
||||||
if (customAsyncAnnotation != AnnotationUtils.getDefaultValue(EnableAsync.class, "annotation")) {
|
if (customAsyncAnnotation != AnnotationUtils.getDefaultValue(EnableAsync.class, "annotation")) {
|
||||||
bpp.setAsyncAnnotationType(customAsyncAnnotation);
|
bpp.setAsyncAnnotationType(customAsyncAnnotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.executor != null) {
|
if (this.executor != null) {
|
||||||
bpp.setExecutor(this.executor);
|
bpp.setExecutor(this.executor);
|
||||||
}
|
}
|
||||||
|
|
||||||
bpp.setProxyTargetClass(this.enableAsync.getBoolean("proxyTargetClass"));
|
bpp.setProxyTargetClass(this.enableAsync.getBoolean("proxyTargetClass"));
|
||||||
bpp.setOrder(this.enableAsync.<Integer>getNumber("order"));
|
bpp.setOrder(this.enableAsync.<Integer>getNumber("order"));
|
||||||
|
|
||||||
return bpp;
|
return bpp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.core.annotation.subpackage.NonPublicAnnotatedClass;
|
import org.springframework.core.annotation.subpackage.NonPublicAnnotatedClass;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -37,6 +38,8 @@ import static org.junit.Assert.*;
|
||||||
import static org.springframework.core.annotation.AnnotationUtils.*;
|
import static org.springframework.core.annotation.AnnotationUtils.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Unit tests for {@link AnnotationUtils}.
|
||||||
|
*
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
|
@ -97,9 +100,9 @@ public class AnnotationUtilsTests {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void findAnnotationPrefersInteracesOverLocalMetaAnnotations() {
|
public void findAnnotationPrefersInterfacesOverLocalMetaAnnotations() {
|
||||||
Component component = AnnotationUtils.findAnnotation(
|
Component component = AnnotationUtils.findAnnotation(
|
||||||
ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, Component.class);
|
ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, Component.class);
|
||||||
|
|
||||||
// By inspecting ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface, one
|
// By inspecting ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface, one
|
||||||
// might expect that "meta2" should be found; however, with the current
|
// 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
|
// inherited class-level annotation; note: @Transactional is inherited
|
||||||
assertEquals(InheritedAnnotationInterface.class,
|
assertEquals(InheritedAnnotationInterface.class,
|
||||||
findAnnotationDeclaringClassForTypes(transactionalCandidateList, InheritedAnnotationInterface.class));
|
findAnnotationDeclaringClassForTypes(transactionalCandidateList, InheritedAnnotationInterface.class));
|
||||||
assertNull(findAnnotationDeclaringClassForTypes(transactionalCandidateList,
|
assertNull(findAnnotationDeclaringClassForTypes(transactionalCandidateList, SubInheritedAnnotationInterface.class));
|
||||||
SubInheritedAnnotationInterface.class));
|
|
||||||
assertEquals(InheritedAnnotationClass.class,
|
assertEquals(InheritedAnnotationClass.class,
|
||||||
findAnnotationDeclaringClassForTypes(transactionalCandidateList, InheritedAnnotationClass.class));
|
findAnnotationDeclaringClassForTypes(transactionalCandidateList, InheritedAnnotationClass.class));
|
||||||
assertEquals(InheritedAnnotationClass.class,
|
assertEquals(InheritedAnnotationClass.class,
|
||||||
|
@ -301,8 +303,7 @@ public class AnnotationUtilsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void findAnnotationFromInterfaceWhenSuperDoesNotImplementMethod()
|
public void findAnnotationFromInterfaceWhenSuperDoesNotImplementMethod() throws Exception {
|
||||||
throws Exception {
|
|
||||||
Method method = SubOfAbstractImplementsInterfaceWithAnnotatedMethod.class.getMethod("foo");
|
Method method = SubOfAbstractImplementsInterfaceWithAnnotatedMethod.class.getMethod("foo");
|
||||||
Order order = findAnnotation(method, Order.class);
|
Order order = findAnnotation(method, Order.class);
|
||||||
assertNotNull(order);
|
assertNotNull(order);
|
||||||
|
@ -322,13 +323,13 @@ public class AnnotationUtilsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Component(value = "meta1")
|
@Component(value="meta1")
|
||||||
@Order
|
@Order
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@interface Meta1 {
|
@interface Meta1 {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component(value = "meta2")
|
@Component(value="meta2")
|
||||||
@Transactional
|
@Transactional
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@interface Meta2 {
|
@interface Meta2 {
|
||||||
|
@ -353,25 +354,20 @@ public class AnnotationUtilsTests {
|
||||||
|
|
||||||
@Order(27)
|
@Order(27)
|
||||||
public void annotatedOnRoot() {
|
public void annotatedOnRoot() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void overrideToAnnotate() {
|
public void overrideToAnnotate() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(27)
|
@Order(27)
|
||||||
public void overrideWithoutNewAnnotation() {
|
public void overrideWithoutNewAnnotation() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notAnnotated() {
|
public void notAnnotated() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromInterfaceImplementedByRoot() {
|
public void fromInterfaceImplementedByRoot() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,21 +375,23 @@ public class AnnotationUtilsTests {
|
||||||
|
|
||||||
@Order(25)
|
@Order(25)
|
||||||
public void annotatedOnLeaf() {
|
public void annotatedOnLeaf() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Order(1)
|
@Order(1)
|
||||||
public void overrideToAnnotate() {
|
public void overrideToAnnotate() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void overrideWithoutNewAnnotation() {
|
public void overrideWithoutNewAnnotation() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Inherited
|
||||||
|
@interface Transactional {
|
||||||
|
}
|
||||||
|
|
||||||
public static abstract class Foo<T> {
|
public static abstract class Foo<T> {
|
||||||
|
|
||||||
@Order(1)
|
@Order(1)
|
||||||
|
@ -405,7 +403,6 @@ public class AnnotationUtilsTests {
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void something(final String arg) {
|
public void something(final String arg) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -474,58 +471,45 @@ public class AnnotationUtilsTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract static class AbstractDoesNotImplementInterfaceWithAnnotatedMethod implements
|
public abstract static class AbstractDoesNotImplementInterfaceWithAnnotatedMethod
|
||||||
InterfaceWithAnnotatedMethod {
|
implements InterfaceWithAnnotatedMethod {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SubOfAbstractImplementsInterfaceWithAnnotatedMethod extends
|
public static class SubOfAbstractImplementsInterfaceWithAnnotatedMethod
|
||||||
AbstractDoesNotImplementInterfaceWithAnnotatedMethod {
|
extends AbstractDoesNotImplementInterfaceWithAnnotatedMethod {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void foo() {
|
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 {
|
public static interface InterfaceWithRepeated {
|
||||||
|
|
||||||
@MyRepeatable("a")
|
@MyRepeatable("a")
|
||||||
@MyRepeatableContainer({ @MyRepeatable("b"), @MyRepeatable("c") })
|
@MyRepeatableContainer({ @MyRepeatable("b"), @MyRepeatable("c") })
|
||||||
@MyRepeatableMeta
|
@MyRepeatableMeta
|
||||||
void foo();
|
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 {
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue