从另一个jar中的类读取属性文件

时间:2012-10-25 13:58:28

标签: spring maven junit

我有一个包含多个maven子项目的项目。使用Spring,JPA,JUnit。

+common
   + WebserviceBindingProvider.java  
+views
   +......
   +src/main/test/TestClass.java
   +src/main/test/resources/mocking.properties

The "common" project has a class that reads the properties file "mocking.properties" that is in the "views" project test folders - src/main/test/resources/
The common.jar is added as dependency to the views project.

The code is something like below.

Resource resource = new ClassPathResource("/mock_endpoints.properties"); 
props = PropertiesLoaderUtils.loadProperties(resource);

当我运行测试用例时,我将“props”视为null。

任何人都可以让我知道我错过了什么。

1 个答案:

答案 0 :(得分:1)

您的TestClass.java应该在src/test/java/mocking.properties应该在src/test/resources/