非spring托管的类使用spring脱管的类。

import org.springframework.beans.BeansException;  
import org.springframework.context.ApplicationContext;  
import org.springframework.context.ApplicationContextAware;  
  
public class SpringUtil implements ApplicationContextAware {  
  
    private static ApplicationContext applicationContext;  
  
    public static ApplicationContext getApplicationContext() {  
        return applicationContext;  
    }  
  
    public void setApplicationContext(ApplicationContext applicationContext)throws BeansException {  
        SpringUtil.applicationContext = applicationContext;  
    }  
}  
<?xml version="1.0"?>  
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">  
  
<beans>   
    <bean id="applicationContext" class="com.test.util.SpringUtil"/>  
</beans>  
private InfoBO infoBOProxy = (InfoBO) SpringUtil.getApplicationContext().getBean("infoBOProxy")

 

posted @ 2016-12-14 21:18  刘威jcw  阅读(714)  评论(0编辑  收藏  举报