I am calling a method called getBanks() (located inside BankService) from inside my Flex app. Here is the BankService class:
@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;
}
}
The problem is that the call to beforeClass() produces the following error:
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
The curious thing about this is that apnycdtg7qgcq1.application.xml is located in my src folder, the same place that the error claims it is looking in. Anyone see the problem here?
The word “resource” as in
addConfigResourceandaddConfigHostResourcetypically means a classpath resource. Likewise,ClassPathXmlApplicationContextis expecting Spring context files on the classpath. Try moving your file onto the classpath and it should work.If you are a Maven user, this mean moving it to
src/main/resources. If you are building with something else, move the file into wherever that tool expects resources to reside, or make sure that when it compiles, it copies XML files onto the classpath (typically where your.classfiles get generated to).