Spring中优雅开发的代码技巧
一、如何获取spring容器对象
1、实现BeanFactoryAware接口,重写setBeanFactory方法
java">@Service
public class PersonService implements BeanFactoryAware {private BeanFactory beanFactory;@Overridepublic void setBeanFactory(BeanFactory beanFactory) throws BeansException {this.beanFactory = beanFactory;}public void add() {Person person = (Person) beanFactory.getBean("person");}
}