In my Spring application, I have a simple properties file located in a folder WEB-INF\classes, so that it DispatcherServletand other other configuration files are in classpath.
The props file is defined DispatcherServletas:
<bean id="propertiesFactory" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location">
<value>/WEB-INF/classes/library.properties</value>
</property>
</bean>
propertiesFactory The bean is entered into the controller:
@Autowired
private Properties propertiesFactory;
And it is used in one of the controller methods as:
if (adminPassword.equals(propertiesFactory.getProperty("adminPassword"))) {
All this works fine, with the exception of a test program that has a line:
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("library-servlet.xml");
What I chose BeanCreationException:
Injection of autowired dependencies failed
Because of:
java.io.FileNotFoundException: class path resource [WEB-INF/classes/library.properties] cannot be opened because it does not exist
But if the whole application can see the props file, why not this program?