【发布时间】:2019-09-07 11:07:27
【问题描述】:
我正在尝试使用 MyConfig.class.getResourceAsStream(/config/test.txt) 读取配置文件夹中的文本文件 - Spring Boot 配置类中的 MyProject/config。
MyProject
-config
-test.txt
-src
-main
-java
-com
-myproject
-configurations
-MyConfig
它总是返回 null 作为未找到的资源。而它可以读取位于 MyProject/src/main/resources 文件夹下的文件。
MyProject
-src
-main
-resources
-test.txt
-java
-com
-myproject
-configurations
-MyConfig
是否需要任何特定的配置来告诉spring-boot检查项目的整个路径?
@Configuration
@EnableAutoConfiguration
public class MyConfig {
@Bean
public Config config() {
return new Config(MyConfig.class.getResourceAsStream("/config/test.txt"); // This doesn't work. The same setup work if I have the file under resources folder.MyConfig.class.getResourceAsStream("/test.txt")
}
}
【问题讨论】:
-
你应该发布一些代码和错误信息
-
显示文件夹结构
标签: java spring-boot