|
16 | 16 |
|
17 | 17 | package org.springframework.boot.autoconfigure.aop;
|
18 | 18 |
|
19 |
| -import org.aspectj.lang.annotation.Aspect; |
20 |
| -import org.aspectj.lang.reflect.Advice; |
21 |
| -import org.aspectj.weaver.AnnotatedElement; |
| 19 | +import org.aspectj.weaver.Advice; |
22 | 20 |
|
| 21 | +import org.springframework.aop.config.AopConfigUtils; |
| 22 | +import org.springframework.beans.factory.BeanFactory; |
| 23 | +import org.springframework.beans.factory.support.BeanDefinitionRegistry; |
23 | 24 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
| 25 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass; |
24 | 26 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
25 | 27 | import org.springframework.context.annotation.Configuration;
|
26 | 28 | import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
|
40 | 42 | * @see EnableAspectJAutoProxy
|
41 | 43 | */
|
42 | 44 | @Configuration(proxyBeanMethods = false)
|
43 |
| -@ConditionalOnClass({ EnableAspectJAutoProxy.class, Aspect.class, Advice.class, AnnotatedElement.class }) |
44 | 45 | @ConditionalOnProperty(prefix = "spring.aop", name = "auto", havingValue = "true", matchIfMissing = true)
|
45 | 46 | public class AopAutoConfiguration {
|
46 | 47 |
|
47 | 48 | @Configuration(proxyBeanMethods = false)
|
48 |
| - @EnableAspectJAutoProxy(proxyTargetClass = false) |
49 |
| - @ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", havingValue = "false", |
50 |
| - matchIfMissing = false) |
51 |
| - public static class JdkDynamicAutoProxyConfiguration { |
| 49 | + @ConditionalOnClass(Advice.class) |
| 50 | + static class AspectJAutoProxyingConfiguration { |
| 51 | + |
| 52 | + @Configuration(proxyBeanMethods = false) |
| 53 | + @EnableAspectJAutoProxy(proxyTargetClass = false) |
| 54 | + @ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", havingValue = "false", |
| 55 | + matchIfMissing = false) |
| 56 | + static class JdkDynamicAutoProxyConfiguration { |
| 57 | + |
| 58 | + } |
| 59 | + |
| 60 | + @Configuration(proxyBeanMethods = false) |
| 61 | + @EnableAspectJAutoProxy(proxyTargetClass = true) |
| 62 | + @ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", havingValue = "true", |
| 63 | + matchIfMissing = true) |
| 64 | + static class CglibAutoProxyConfiguration { |
| 65 | + |
| 66 | + } |
52 | 67 |
|
53 | 68 | }
|
54 | 69 |
|
55 | 70 | @Configuration(proxyBeanMethods = false)
|
56 |
| - @EnableAspectJAutoProxy(proxyTargetClass = true) |
| 71 | + @ConditionalOnMissingClass("org.aspectj.weaver.Advice") |
57 | 72 | @ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", havingValue = "true",
|
58 | 73 | matchIfMissing = true)
|
59 |
| - public static class CglibAutoProxyConfiguration { |
| 74 | + static class ClassProxyingConfiguration { |
| 75 | + |
| 76 | + ClassProxyingConfiguration(BeanFactory beanFactory) { |
| 77 | + if (beanFactory instanceof BeanDefinitionRegistry) { |
| 78 | + BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; |
| 79 | + AopConfigUtils.registerAutoProxyCreatorIfNecessary(registry); |
| 80 | + AopConfigUtils.forceAutoProxyCreatorToUseClassProxying(registry); |
| 81 | + } |
| 82 | + } |
60 | 83 |
|
61 | 84 | }
|
62 | 85 |
|
|
0 commit comments