非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")
原文地址:https://www.cnblogs.com/itjcw/p/6180930.html