自定义Spring ApplicationContext 支持动态订阅spring配置

public class StringXmlApplicationContext extends AbstractXmlApplicationContext {

private Resource[] configResources;

 

public StringXmlApplicationContext(String stringXml) {

  this(new String[] { stringXml }, null);

}

 

public StringXmlApplicationContext(String[] stringXmls) {

  this(stringXmls, null);

}

 

public StringXmlApplicationContext(String[] stringXmls, ApplicationContext parent) {

  super(parent);

  this.configResources = new Resource[stringXmls.length];

  for (int i = 0; i < stringXmls.length; i++) {

    this.configResources[i] = new ByteArrayResource(stringXmls[i].getBytes());

  }

  refresh();

}

 

protected Resource[] getConfigResources() {

  return this.configResources;

}

 

public ClassLoader getClassLoader() { 

       return this.getClass().getClassLoader();

    }

}

posted @ 2017-04-27 17:23  李高峰  阅读(470)  评论(0编辑  收藏  举报