I want to create bean using BeanFactory, but I am getting an exeception: java.io.FileNotFoundException: \\WEB-INF\businesscaliber-servlet.xml.
Resource res = new FileSystemResource("//WEB-INF//businesscaliber-servlet.xml");
BeanFactory factory = new XmlBeanFactory(res);
if (factory != null && beanId != null) {
obj = factory.getBean(beanId);
}
he its working using this
ApplicationContext ctx = new FileSystemXmlApplicationContext(“classpath*:/WEB-INF/businesscaliber-servlet.xml”);
I believe you need to specify an absolute path and not a Web application relative path to
FileSystemResource.Try using
ServletContextResourceinstead.The only issue is you need the
ServletContextso:It’s worth noting that ideally you would retrieve this from an
ApplicationContext. From 4.4 Resource Loader of the Spring Reference:So this is the preferred method of retrieving resources.
Alternatively since
/WEB-INF/is technically in the classpath you can use theclasspath:prefix (as per your comment) or useClassPathXmlApplicationContext(which will automatically return classpath resources).Also theres no need to put double forward slashes in. Not sure why you’re doing this. Perhaps a holdover from double backslashes, which are necessary?