Getting error while reading XML file from initializing bean from servlet.xml
posted 6 years ago
I have defined one Class using beanFactory method. That bean is defiend in servlet.xml. This xml method will be called from DispatcherServlet of Spring Framework.
I want to pass path of XML file in that bean. I have tried to pass that path as relative path. I have stored that XML file in WEB-INF directory. But while trying to read that file, I am getting error like File does not exist. But if I'll provide absolute path, then it's work properly. Can Anyone suggest how to pass relative path in beanFactory.
I am using eclipse 3.5 as an editor and SPRING/HIBERNATE in my project.
The code of my servlet.xml is...
<bean id="handlerMappingClass" init-method="getMapOfHandler" class="com.mapper.HandlerMappingFactory">
<property name="configFilePath" value="WEB-INF/handlerMapEntries.xml"/>
The code of my HandlerMappingFactory class is...
ClassPathResource configFileObj = new ClassPathResource(configFilePath);
fileObj = configFileObj.getFile(); // Over here, If path is relative then "File not found" error is coming. If path is absolute then it works fine.
//Remaining code to read XML file.