Thursday, July 10, 2008

Spring Configuration Issue - How to specify path to config file

BeanFactory factory =
new XmlBeanFactory(new FileSystemResource(".\\src\\applicationContext.xml"));


where "applicationContext.xml" is the spring configuration file's name.

Note: It is assumed that this file is under folder "src"

Method #2:
Better use ClassPathResource instead. This obviates the need for
using the entire path to the physical file.

It works since src is on the classpath.

Eg:
import org.springframework.core.io.ClassPathResource;
BeanFactory factory =
new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));

No comments: