|
28 | 28 | import org.springframework.aop.scope.ScopedProxyFactoryBean;
|
29 | 29 | import org.springframework.asm.Opcodes;
|
30 | 30 | import org.springframework.asm.Type;
|
| 31 | +import org.springframework.beans.factory.BeanDefinitionStoreException; |
31 | 32 | import org.springframework.beans.factory.BeanFactory;
|
32 | 33 | import org.springframework.beans.factory.BeanFactoryAware;
|
33 | 34 | import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
|
37 | 38 | import org.springframework.beans.factory.support.SimpleInstantiationStrategy;
|
38 | 39 | import org.springframework.cglib.core.ClassGenerator;
|
39 | 40 | import org.springframework.cglib.core.ClassLoaderAwareGeneratorStrategy;
|
| 41 | +import org.springframework.cglib.core.CodeGenerationException; |
40 | 42 | import org.springframework.cglib.core.SpringNamingPolicy;
|
41 | 43 | import org.springframework.cglib.proxy.Callback;
|
42 | 44 | import org.springframework.cglib.proxy.CallbackFilter;
|
@@ -106,12 +108,19 @@ public Class<?> enhance(Class<?> configClass, @Nullable ClassLoader classLoader)
|
106 | 108 | }
|
107 | 109 | return configClass;
|
108 | 110 | }
|
109 |
| - Class<?> enhancedClass = createClass(newEnhancer(configClass, classLoader)); |
110 |
| - if (logger.isTraceEnabled()) { |
111 |
| - logger.trace(String.format("Successfully enhanced %s; enhanced class name is: %s", |
112 |
| - configClass.getName(), enhancedClass.getName())); |
| 111 | + try { |
| 112 | + Class<?> enhancedClass = createClass(newEnhancer(configClass, classLoader)); |
| 113 | + if (logger.isTraceEnabled()) { |
| 114 | + logger.trace(String.format("Successfully enhanced %s; enhanced class name is: %s", |
| 115 | + configClass.getName(), enhancedClass.getName())); |
| 116 | + } |
| 117 | + return enhancedClass; |
| 118 | + } |
| 119 | + catch (CodeGenerationException ex) { |
| 120 | + throw new BeanDefinitionStoreException("Could not enhance configuration class [" + configClass.getName() + |
| 121 | + "]. Consider declaring @Configuration(proxyBeanMethods=false) without inter-bean references " + |
| 122 | + "between @Bean methods on the configuration class, avoiding the need for CGLIB enhancement.", ex); |
113 | 123 | }
|
114 |
| - return enhancedClass; |
115 | 124 | }
|
116 | 125 |
|
117 | 126 | /**
|
|
0 commit comments