1 16 17 package org.springframework.context; 18 19 import org.springframework.beans.BeansException; 20 import org.springframework.beans.factory.BeanFactory; 21 import org.springframework.beans.factory.LifecycleBean; 22 23 29 public class LifecycleContextBean extends LifecycleBean implements ApplicationContextAware { 30 31 protected ApplicationContext owningContext; 32 33 public void setBeanFactory(BeanFactory beanFactory) { 34 super.setBeanFactory(beanFactory); 35 if (this.owningContext != null) 36 throw new RuntimeException ("Factory called setBeanFactory after setApplicationContext"); 37 } 38 39 public void afterPropertiesSet() { 40 super.afterPropertiesSet(); 41 if (this.owningContext == null) 42 throw new RuntimeException ("Factory didn't call setAppliationContext before afterPropertiesSet on lifecycle bean"); 43 } 44 45 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 46 if (this.owningFactory == null) 47 throw new RuntimeException ("Factory called setApplicationContext before setBeanFactory"); 48 49 this.owningContext = applicationContext; 50 } 51 52 } 53 | Popular Tags |