1

测试类:

@RunWith(SpringRunner.class)
@SpringBootTest
public class FileInterfaceTest {
 @Test
 public void contextLoads() {
 }

}

应用 :

应用配置:

      @Configuration
      @ImportResource({ "classpath:process-flows.xml" })
      public class AppConfig {
               }

有 Bootstraploader 类。

错误:

       java.lang.IllegalStateException: Failed to load ApplicationContext
       Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [file.properties] cannot be opened because it does not exist

资源位置:

  src/main/resources
          ---process-flow.xml
          --- process.yml
  src/main/resources/env/cconfig
          --- file.properties
4

2 回答 2

0

您的文件夹结构包含错字:src/main/resources/env/cconfig必须是src/main/resources/env/config

正如Spring Externalized Configuration中定义的那样,SpringApplication从以下位置的文件中加载属性application.properties并将它们添加到 Spring 环境中:

  • 当前目录的/config子目录
  • 当前目录
  • 一个类路径/config
  • 类路径根
于 2018-07-17T11:02:51.523 回答
0

除了“cconfig”文件夹名称(不确定这是否是拼写错误),我还看到您的 @ImportResource 被提及为 classpath:process-flows.xml 但是您的资源文件夹具有名为 process-flow.xml 的文件

如果这也不是拼写错误,请通过将 process-flow.xml 重命名为 process-flows.xml 添加一个“s”并重试

于 2018-07-19T02:51:57.260 回答