单例模式

public class GetObectByName{
    Object  object=null;
    static ApplicationContext applicationContext=null;
private static GetObectByName uniqueInstance = new GetObectByName();

private GetObectByName(){}

public static GetObectByName getInstance() {
if(uniqueInstance==null){
uniqueInstance = new GetObectByName();
}
return uniqueInstance;
}

public  Object getObjectByName(String name){
object =applicationContext.getBean(name);  
return object;
}

public  void getObjectByName(ServletConfig config){
//服务启动过程中加载beanfactory
applicationContext =
        WebApplicationContextUtils.getWebApplicationContext(config.getServletContext());  


}


}
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页