1 16 17 package org.springframework.aop.config; 18 19 import org.w3c.dom.Element ; 20 21 import org.springframework.beans.factory.config.BeanDefinition; 22 import org.springframework.beans.factory.support.BeanDefinitionBuilder; 23 import org.springframework.beans.factory.xml.BeanDefinitionParser; 24 import org.springframework.beans.factory.xml.ParserContext; 25 import org.springframework.util.ClassUtils; 26 27 34 class SpringConfiguredBeanDefinitionParser implements BeanDefinitionParser { 35 36 private static final String BEAN_CONFIGURER_CLASS_NAME = 37 "org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect"; 38 39 40 private boolean registered; 41 42 43 public BeanDefinition parse(Element element, ParserContext parserContext) { 44 if (!this.registered) { 45 BeanDefinitionBuilder builder = 46 BeanDefinitionBuilder.rootBeanDefinition(getBeanConfigurerClass(), "aspectOf"); 47 builder.setSource(parserContext.extractSource(element)); 48 parserContext.getReaderContext().registerWithGeneratedName(builder.getBeanDefinition()); 49 this.registered = true; 50 } 51 return null; 52 } 53 54 58 private static Class getBeanConfigurerClass() throws IllegalStateException { 59 try { 60 return ClassUtils.forName(BEAN_CONFIGURER_CLASS_NAME); 61 } 62 catch (Throwable ex) { 63 throw new IllegalStateException ( 64 "Unable to load aspect class [" + BEAN_CONFIGURER_CLASS_NAME + 65 "]: cannot use @Configurable. Root cause: " + ex); 66 } 67 } 68 69 } 70 | Popular Tags |