Consolidate annotation processing constants
Consolidating internal bean name and aspect class name constats within AnnotationConfigUtils to allow access from both the context.config and context.annotation packages without creating a relationship between the two of them (they are unrelated leaf nodes in the packaging currently). The .transaction module does not have a similar utils class and already has a relationship from transaction.config -> transaction.annotation, so placing the constants in .annotation.TransactionManagementCapability to be referenced by .config.AnnotationDrivenBeanDefinitionParser
This commit is contained in:
parent
9a271ce6c9
commit
2bc3527f76
|
@ -16,6 +16,10 @@
|
|||
|
||||
package org.springframework.cache.config;
|
||||
|
||||
import static org.springframework.context.annotation.AnnotationConfigUtils.CACHE_ADVISOR_BEAN_NAME;
|
||||
import static org.springframework.context.annotation.AnnotationConfigUtils.CACHE_ASPECT_BEAN_NAME;
|
||||
import static org.springframework.context.annotation.AnnotationConfigUtils.CACHE_ASPECT_CLASS_NAME;
|
||||
|
||||
import org.springframework.aop.config.AopNamespaceUtils;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
|
@ -49,18 +53,6 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
|
|||
private static final String DEFAULT_CACHE_MANAGER_BEAN_NAME = "cacheManager";
|
||||
|
||||
|
||||
/**
|
||||
* The bean name of the internally managed cache advisor (mode="proxy").
|
||||
*/
|
||||
public static final String CACHE_ADVISOR_BEAN_NAME = "org.springframework.cache.config.internalCacheAdvisor";
|
||||
|
||||
/**
|
||||
* The bean name of the internally managed cache aspect (mode="aspectj").
|
||||
*/
|
||||
public static final String CACHE_ASPECT_BEAN_NAME = "org.springframework.cache.config.internalCacheAspect";
|
||||
|
||||
private static final String CACHE_ASPECT_CLASS_NAME = "org.springframework.cache.aspectj.AnnotationCacheAspect";
|
||||
|
||||
/**
|
||||
* Parses the '<code><cache:annotation-driven/></code>' tag. Will
|
||||
* {@link AopNamespaceUtils#registerAutoProxyCreatorIfNecessary register an AutoProxyCreator}
|
||||
|
|
|
@ -70,6 +70,48 @@ public class AnnotationConfigUtils {
|
|||
public static final String COMMON_ANNOTATION_PROCESSOR_BEAN_NAME =
|
||||
"org.springframework.context.annotation.internalCommonAnnotationProcessor";
|
||||
|
||||
/**
|
||||
* The bean name of the internally managed Scheduled annotation processor.
|
||||
*/
|
||||
public static final String SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME =
|
||||
"org.springframework.context.annotation.internalScheduledAnnotationProcessor";
|
||||
|
||||
/**
|
||||
* The bean name of the internally managed Async annotation processor.
|
||||
*/
|
||||
public static final String ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME =
|
||||
"org.springframework.context.annotation.internalAsyncAnnotationProcessor";
|
||||
|
||||
/**
|
||||
* The bean name of the internally managed AspectJ async execution aspect.
|
||||
*/
|
||||
public static final String ASYNC_EXECUTION_ASPECT_BEAN_NAME =
|
||||
"org.springframework.scheduling.config.internalAsyncExecutionAspect";
|
||||
|
||||
/**
|
||||
* The class name of the AspectJ async execution aspect.
|
||||
*/
|
||||
public static final String ASYNC_EXECUTION_ASPECT_CLASS_NAME =
|
||||
"org.springframework.scheduling.aspectj.AnnotationAsyncExecutionAspect";
|
||||
|
||||
/**
|
||||
* The bean name of the internally managed cache advisor.
|
||||
*/
|
||||
public static final String CACHE_ADVISOR_BEAN_NAME =
|
||||
"org.springframework.cache.config.internalCacheAdvisor";
|
||||
|
||||
/**
|
||||
* The bean name of the internally managed cache aspect.
|
||||
*/
|
||||
public static final String CACHE_ASPECT_BEAN_NAME =
|
||||
"org.springframework.cache.config.internalCacheAspect";
|
||||
|
||||
/**
|
||||
* The class name of the AspectJ caching aspect.
|
||||
*/
|
||||
public static final String CACHE_ASPECT_CLASS_NAME =
|
||||
"org.springframework.cache.aspectj.AnnotationCacheAspect";
|
||||
|
||||
/**
|
||||
* The bean name of the internally managed JPA annotation processor.
|
||||
*/
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
|||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
|
@ -35,30 +36,37 @@ import org.springframework.util.StringUtils;
|
|||
* @author Mark Fisher
|
||||
* @author Juergen Hoeller
|
||||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
* @since 3.0
|
||||
*/
|
||||
public class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
|
||||
|
||||
/**
|
||||
* The bean name of the internally managed async annotation processor (mode="proxy").
|
||||
* @deprecated as of Spring 3.1 in favor of
|
||||
* {@link AnnotationConfigUtils#ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME}
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME =
|
||||
"org.springframework.scheduling.annotation.internalAsyncAnnotationProcessor";
|
||||
AnnotationConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME;
|
||||
|
||||
/**
|
||||
* The bean name of the internally managed transaction aspect (mode="aspectj").
|
||||
* @deprecated as of Spring 3.1 in favor of
|
||||
* {@link AnnotationConfigUtils#ASYNC_EXECUTION_ASPECT_BEAN_NAME}
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String ASYNC_EXECUTION_ASPECT_BEAN_NAME =
|
||||
"org.springframework.scheduling.config.internalAsyncExecutionAspect";
|
||||
|
||||
private static final String ASYNC_EXECUTION_ASPECT_CLASS_NAME =
|
||||
"org.springframework.scheduling.aspectj.AnnotationAsyncExecutionAspect";
|
||||
AnnotationConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME;
|
||||
|
||||
/**
|
||||
* The bean name of the internally managed scheduled annotation processor.
|
||||
* @deprecated as of Spring 3.1 in favor of
|
||||
* {@link AnnotationConfigUtils#SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME}
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME =
|
||||
"org.springframework.scheduling.annotation.internalScheduledAnnotationProcessor";
|
||||
AnnotationConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME;
|
||||
|
||||
|
||||
public BeanDefinition parse(Element element, ParserContext parserContext) {
|
||||
|
@ -78,7 +86,7 @@ public class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParse
|
|||
}
|
||||
else {
|
||||
// mode="proxy"
|
||||
if (registry.containsBeanDefinition(ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME)) {
|
||||
if (registry.containsBeanDefinition(AnnotationConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME)) {
|
||||
parserContext.getReaderContext().error(
|
||||
"Only one AsyncAnnotationBeanPostProcessor may exist within the context.", source);
|
||||
}
|
||||
|
@ -93,11 +101,11 @@ public class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParse
|
|||
if (Boolean.valueOf(element.getAttribute(AopNamespaceUtils.PROXY_TARGET_CLASS_ATTRIBUTE))) {
|
||||
builder.addPropertyValue("proxyTargetClass", true);
|
||||
}
|
||||
registerPostProcessor(parserContext, builder, ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME);
|
||||
registerPostProcessor(parserContext, builder, AnnotationConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
if (registry.containsBeanDefinition(SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME)) {
|
||||
if (registry.containsBeanDefinition(AnnotationConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME)) {
|
||||
parserContext.getReaderContext().error(
|
||||
"Only one ScheduledAnnotationBeanPostProcessor may exist within the context.", source);
|
||||
}
|
||||
|
@ -109,7 +117,7 @@ public class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParse
|
|||
if (StringUtils.hasText(scheduler)) {
|
||||
builder.addPropertyReference("scheduler", scheduler);
|
||||
}
|
||||
registerPostProcessor(parserContext, builder, SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME);
|
||||
registerPostProcessor(parserContext, builder, AnnotationConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME);
|
||||
}
|
||||
|
||||
// Finally register the composite component.
|
||||
|
@ -119,16 +127,17 @@ public class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParse
|
|||
}
|
||||
|
||||
private void registerAsyncExecutionAspect(Element element, ParserContext parserContext) {
|
||||
if (!parserContext.getRegistry().containsBeanDefinition(ASYNC_EXECUTION_ASPECT_BEAN_NAME)) {
|
||||
if (!parserContext.getRegistry().containsBeanDefinition(AnnotationConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME)) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
ASYNC_EXECUTION_ASPECT_CLASS_NAME);
|
||||
AnnotationConfigUtils.ASYNC_EXECUTION_ASPECT_CLASS_NAME);
|
||||
builder.setFactoryMethod("aspectOf");
|
||||
String executor = element.getAttribute("executor");
|
||||
if (StringUtils.hasText(executor)) {
|
||||
builder.addPropertyReference("executor", executor);
|
||||
}
|
||||
parserContext.registerBeanComponent(
|
||||
new BeanComponentDefinition(builder.getBeanDefinition(), ASYNC_EXECUTION_ASPECT_BEAN_NAME));
|
||||
new BeanComponentDefinition(builder.getBeanDefinition(),
|
||||
AnnotationConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.junit.Test;
|
|||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigUtils;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
|
@ -42,27 +43,26 @@ public class AnnotationDrivenBeanDefinitionParserTests {
|
|||
|
||||
@Test
|
||||
public void asyncPostProcessorRegistered() {
|
||||
assertTrue(context.containsBean(
|
||||
AnnotationDrivenBeanDefinitionParser.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||
assertTrue(context.containsBean(AnnotationConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scheduledPostProcessorRegistered() {
|
||||
assertTrue(context.containsBean(
|
||||
AnnotationDrivenBeanDefinitionParser.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||
AnnotationConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asyncPostProcessorExecutorReference() {
|
||||
Object executor = context.getBean("testExecutor");
|
||||
Object postProcessor = context.getBean(AnnotationDrivenBeanDefinitionParser.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME);
|
||||
Object postProcessor = context.getBean(AnnotationConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME);
|
||||
assertSame(executor, new DirectFieldAccessor(postProcessor).getPropertyValue("executor"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scheduledPostProcessorSchedulerReference() {
|
||||
Object scheduler = context.getBean("testScheduler");
|
||||
Object postProcessor = context.getBean(AnnotationDrivenBeanDefinitionParser.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME);
|
||||
Object postProcessor = context.getBean(AnnotationConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME);
|
||||
assertSame(scheduler, new DirectFieldAccessor(postProcessor).getPropertyValue("scheduler"));
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
|||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.context.config.AbstractSpecificationBeanDefinitionParser;
|
||||
import org.springframework.context.config.FeatureSpecification;
|
||||
import org.springframework.transaction.annotation.TransactionManagementCapability;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
|
@ -46,21 +47,26 @@ import org.w3c.dom.Element;
|
|||
* @author Rob Harrop
|
||||
* @author Chris Beams
|
||||
* @since 2.0
|
||||
* @see TxAnnotationDriven
|
||||
*/
|
||||
class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
|
||||
|
||||
/**
|
||||
* The bean name of the internally managed transaction advisor (mode="proxy").
|
||||
* @deprecated as of Spring 3.1 in favor of
|
||||
* {@link TransactionManagementCapability#TRANSACTION_ADVISOR_BEAN_NAME}
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String TRANSACTION_ADVISOR_BEAN_NAME =
|
||||
TxAnnotationDrivenExecutor.TRANSACTION_ADVISOR_BEAN_NAME;
|
||||
TransactionManagementCapability.TRANSACTION_ADVISOR_BEAN_NAME;
|
||||
|
||||
/**
|
||||
* The bean name of the internally managed transaction aspect (mode="aspectj").
|
||||
* @deprecated as of Spring 3.1 in favor of
|
||||
* {@link TransactionManagementCapability#TRANSACTION_ASPECT_BEAN_NAME}
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String TRANSACTION_ASPECT_BEAN_NAME =
|
||||
TxAnnotationDrivenExecutor.TRANSACTION_ASPECT_BEAN_NAME;
|
||||
TransactionManagementCapability.TRANSACTION_ASPECT_BEAN_NAME;
|
||||
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue