Skip to content

Commit 981d449

Browse files
committed
AspectJWeavingEnabler registered with well-defined bean name (and therefore once only)
Issue: SPR-14373
1 parent 0de85e3 commit 981d449

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

spring-context/src/main/java/org/springframework/context/config/LoadTimeWeaverBeanDefinitionParser.java

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
import org.w3c.dom.Element;
2020

2121
import org.springframework.beans.factory.config.BeanDefinition;
22+
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
2223
import org.springframework.beans.factory.support.AbstractBeanDefinition;
2324
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
2425
import org.springframework.beans.factory.support.RootBeanDefinition;
@@ -36,15 +37,22 @@
3637
*/
3738
class LoadTimeWeaverBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
3839

39-
private static final String WEAVER_CLASS_ATTRIBUTE = "weaver-class";
40+
/**
41+
* The bean name of the internally managed AspectJ weaving enabler.
42+
* @since 4.3.1
43+
*/
44+
public static final String ASPECTJ_WEAVING_ENABLER_BEAN_NAME =
45+
"org.springframework.context.config.internalAspectJWeavingEnabler";
4046

41-
private static final String ASPECTJ_WEAVING_ATTRIBUTE = "aspectj-weaving";
47+
private static final String ASPECTJ_WEAVING_ENABLER_CLASS_NAME =
48+
"org.springframework.context.weaving.AspectJWeavingEnabler";
4249

4350
private static final String DEFAULT_LOAD_TIME_WEAVER_CLASS_NAME =
4451
"org.springframework.context.weaving.DefaultContextLoadTimeWeaver";
4552

46-
private static final String ASPECTJ_WEAVING_ENABLER_CLASS_NAME =
47-
"org.springframework.context.weaving.AspectJWeavingEnabler";
53+
private static final String WEAVER_CLASS_ATTRIBUTE = "weaver-class";
54+
55+
private static final String ASPECTJ_WEAVING_ATTRIBUTE = "aspectj-weaving";
4856

4957

5058
@Override
@@ -65,9 +73,11 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinit
6573
builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
6674

6775
if (isAspectJWeavingEnabled(element.getAttribute(ASPECTJ_WEAVING_ATTRIBUTE), parserContext)) {
68-
RootBeanDefinition weavingEnablerDef = new RootBeanDefinition();
69-
weavingEnablerDef.setBeanClassName(ASPECTJ_WEAVING_ENABLER_CLASS_NAME);
70-
parserContext.getReaderContext().registerWithGeneratedName(weavingEnablerDef);
76+
if (!parserContext.getRegistry().containsBeanDefinition(ASPECTJ_WEAVING_ENABLER_BEAN_NAME)) {
77+
RootBeanDefinition def = new RootBeanDefinition(ASPECTJ_WEAVING_ENABLER_CLASS_NAME);
78+
parserContext.registerBeanComponent(
79+
new BeanComponentDefinition(def, ASPECTJ_WEAVING_ENABLER_BEAN_NAME));
80+
}
7181

7282
if (isBeanConfigurerAspectEnabled(parserContext.getReaderContext().getBeanClassLoader())) {
7383
new SpringConfiguredBeanDefinitionParser().parse(element, parserContext);

0 commit comments

Comments
 (0)