Я считаю, что проблема в том, что ваш дочерний контекст обновляется до установки родительского контекста.
Вот соответствующие конструкторы из ClassPathXmlApplicationContext
:
// this is the constructor that 'context' is using, and refresh is defaulted to true
public ClassPathXmlApplicationContext(String... configLocations) throws BeansException {
this(configLocations, true, null);
}
// the constructor that both others are calling
public ClassPathXmlApplicationContext(String[] configLocations, boolean refresh, ApplicationContext parent)
throws BeansException {
super(parent);
setConfigLocations(configLocations);
if (refresh) {
// you don't want to refresh until your parent context is set
refresh();
}
}
// the constructor I think you should use, it will set the parent first and then refresh
public ClassPathXmlApplicationContext(String[] configLocations, ApplicationContext parent) throws BeansException {
this(configLocations, true, parent);
}
Я бы вместо этого использовалпоследний конструктор, так что родительский контекст устанавливается до вызова refresh()
.
Вот так:
String[] xmlFies=new String[1];
xmlFies[0]="applicationContext.xml";
ClassPathXmlApplicationContext parentContext = new ClassPathXmlApplicationContext("tokenConfiguration.xml");
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(xmlFies, parentContext);
. . .