【问题标题】:Reading properties file from a class which is in another jar从另一个 jar 中的类中读取属性文件
【发布时间】:2012-10-25 13:58:28
【问题描述】:

我有一个包含多个 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);

当我运行测试用例时,我得到的“道具”为空。

谁能告诉我我错过了什么。

【问题讨论】:

    标签: spring maven junit


    【解决方案1】:

    您的TestClass.java 应位于src/test/java/ 中,您的mocking.properties 应位于src/test/resources/ 中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-19
      • 1970-01-01
      • 2012-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多