1 16 17 package org.springframework.beans.factory.annotation; 18 19 import org.springframework.beans.factory.wiring.BeanWiringInfo; 20 import org.springframework.beans.factory.wiring.BeanWiringInfoResolver; 21 import org.springframework.util.Assert; 22 import org.springframework.util.ClassUtils; 23 24 37 public class AnnotationBeanWiringInfoResolver implements BeanWiringInfoResolver { 38 39 public BeanWiringInfo resolveWiringInfo(Object beanInstance) { 40 Assert.notNull(beanInstance, "Bean instance must not be null"); 41 Configurable annotation = beanInstance.getClass().getAnnotation(Configurable.class); 42 return (annotation != null ? buildWiringInfo(beanInstance, annotation) : null); 43 } 44 45 51 protected BeanWiringInfo buildWiringInfo(Object beanInstance, Configurable annotation) { 52 if (!Autowire.NO.equals(annotation.autowire())) { 53 return new BeanWiringInfo(annotation.autowire().value(), annotation.dependencyCheck()); 54 } 55 else { 56 String beanName = 57 (!"".equals(annotation.value()) ? annotation.value() : getDefaultBeanName(beanInstance)); 58 return new BeanWiringInfo(beanName); 59 } 60 } 61 62 70 protected String getDefaultBeanName(Object beanInstance) { 71 return ClassUtils.getUserClass(beanInstance).getName(); 72 } 73 74 } 75 | Popular Tags |