在我的Spring應用程序中,我有一個位於文件夾WEB-INF\classes
中的簡單屬性文件, DispatcherServlet
和各種其他配置文件在classpath
。java.io.FileNotFoundException:類路徑資源[WEB-INF/classes/library.properties]無法打開,因爲它不存在
<bean id="propertiesFactory" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location">
<value>/WEB-INF/classes/library.properties</value>
</property>
</bean>
的propertiesFactory
豆被注入到一控制器:
@Autowired
private Properties propertiesFactory;
和In組成的控制器的方法作爲一種中:
道具文件在DispatcherServlet
所限定
if (adminPassword.equals(propertiesFactory.getProperty("adminPassword"))) {
這一切都完美的作品,除了一個測試專業克如下其中有一行:
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("library-servlet.xml");
會拋出一個BeanCreationException
:
Injection of autowired dependencies failed
因爲:
java.io.FileNotFoundException: class path resource [WEB-INF/classes/library.properties] cannot be opened because it does not exist
但如果整個應用程序可以看到道具文件,何樂不爲一個程序?
library-servlet.xml文件中有什麼... ??? –
在\ WEB-INF \ classes中。 –
我在問關於library-servlet.xml的內容 –