1
1
/*
2
- * Copyright 2002-2011 the original author or authors.
2
+ * Copyright 2002-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
19
19
import org .w3c .dom .Element ;
20
20
21
21
import org .springframework .beans .factory .config .BeanDefinition ;
22
+ import org .springframework .beans .factory .parsing .BeanComponentDefinition ;
22
23
import org .springframework .beans .factory .support .AbstractBeanDefinition ;
23
24
import org .springframework .beans .factory .support .BeanDefinitionBuilder ;
24
25
import org .springframework .beans .factory .support .RootBeanDefinition ;
36
37
*/
37
38
class LoadTimeWeaverBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
38
39
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" ;
40
46
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" ;
42
49
43
50
private static final String DEFAULT_LOAD_TIME_WEAVER_CLASS_NAME =
44
51
"org.springframework.context.weaving.DefaultContextLoadTimeWeaver" ;
45
52
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" ;
48
56
49
57
50
58
@ Override
@@ -65,9 +73,11 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinit
65
73
builder .setRole (BeanDefinition .ROLE_INFRASTRUCTURE );
66
74
67
75
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
+ }
71
81
72
82
if (isBeanConfigurerAspectEnabled (parserContext .getReaderContext ().getBeanClassLoader ())) {
73
83
new SpringConfiguredBeanDefinitionParser ().parse (element , parserContext );
0 commit comments