我从Flex应用程序内部调用了一个名为getBanks()的方法(位于BankService内)。这是BankService类:
@org.springframework.stereotype.Service("com.apollo.counterpartcontacts.service.BankService")
@org.springframework.flex.remoting.RemotingDestination("com.apollo.counterpartcontacts.service.IBankService")
public class BankService extends _BankService {
private Logger logger = LoggerFactory.getLogger(getClass());
private ApplicationContext applicationContext;
private List<String> configHostResources = new ArrayList<String>();
private List<String> configResources = new ArrayList<String>();
private PersistenceManager persistenceManager;
@BeforeClass
public void beforeClass() {
try {
addConfigResource("application.xml");
addConfigHostResource("application.xml");
}
catch (UnknownHostException e) {
logger.error("Error loading host specific resource", e);
}
List<String> aList = new ArrayList<String>();
aList.addAll(configHostResources);
aList.addAll(configResources);
String[] aConfigArray = new String[aList.size()];
aConfigArray = aList.toArray(aConfigArray);
applicationContext = new ClassPathXmlApplicationContext(aConfigArray);
persistenceManager = (PersistenceManager) applicationContext.getBean("persistenceManager");
}
void addConfigResource(String aConfigName) {
logger.info("Adding a config: " + aConfigName);
configResources.add(aConfigName);
}
public void addConfigHostResource(final String theSuffix) throws UnknownHostException {
String aHostName = InetAddress.getLocalHost().getHostName();
String aConfigName = aHostName.toLowerCase() + "." + theSuffix;
logger.info("Adding a host config: " + aConfigName);
configHostResources.add(aConfigName);
}
private org.springframework.orm.hibernate3.HibernateTemplate hibernateTemplate;
@org.springframework.beans.factory.annotation.Autowired
public void setHibernateTemplate(org.springframework.orm.hibernate3.HibernateTemplate hibernateTemplateValue) {
hibernateTemplate = hibernateTemplateValue;
}
public org.springframework.orm.hibernate3.HibernateTemplate getHibernateTemplate() {
return hibernateTemplate;
}
public List getBanks(){
beforeClass();
List allBanks = persistenceManager.getBanks();
return allBanks;
}
}
问题是对beforeClass()的调用会产生以下错误:
flex.messaging.MessageException: org.springframework.beans.factory.BeanDefinitionStoreException : IOException parsing XML document from class path resource [apnycdtg7qgcq1.application.xml]; nested exception is java.io.FileNotFoundException: class path resource [apnycdtg7qgcq1.application.xml] cannot be opened because it does not exist
关于这一点的奇怪之处在于apnycdtg7qgcq1.application.xml
位于我的src文件夹中,与错误声称它正在查找的位置相同。有人在这里看到问题吗?
答案 0 :(得分:0)
addConfigResource
和addConfigHostResource
中的“资源”一词通常表示类路径资源。同样,ClassPathXmlApplicationContext
期望类路径上的Spring上下文文件。尝试将文件移动到类路径上,它应该可以工作。
如果您是Maven用户,则表示将其移至src/main/resources
。如果要使用其他内容构建,请将文件移动到该工具期望资源驻留的位置,或者确保在编译时将文件复制到类路径(通常是生成.class
文件的位置)。