在SSH2的环境下,我想用JUnit做单元测试。在我的Spring配置文件里引用了一个properties文件,代码片段如下:<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><beans>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/config/common-config.properties" />
</bean>
用Tomcat启动的时候可以用。
但是,用Junit做单元测试的时候,就会报这样的错误:
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [WEB-INF/config/common-config.properties] cannot be opened because it does not exist说明:我的Spring配置文件和properties文件在同一目录下,也就是:WEB-INF/config/ 下请问这是为什么?
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><beans>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/config/common-config.properties" />
</bean>
用Tomcat启动的时候可以用。
但是,用Junit做单元测试的时候,就会报这样的错误:
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [WEB-INF/config/common-config.properties] cannot be opened because it does not exist说明:我的Spring配置文件和properties文件在同一目录下,也就是:WEB-INF/config/ 下请问这是为什么?
tomcat启动时工程的根目录是/web-info/上层目录,而testcase的根目录是class
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="file:D:/workspace_ss/test168/web/WEB-INF/config/common-config.properties" />
</bean>
绝对路径是可以的,谢谢高人。