【发布时间】:2018-03-26 18:20:29
【问题描述】:
我要加载位于以下位置的 html 文件:
在独立的spring boot jar 应用程序中使用。
这种方法导致FileSystemNotFoundException
new InputStreamReader(
getClass().getResourceAsStream("/email-templates/html-email.html")
)
使用
@Autowired
private ResourceLoader resourceLoader;
...
resourceLoader.getResource("classpath:email-templates/html-email.html");
导致NullPointerException。
能否请您指定如何在 spring boot jar 中正确加载文件。
【问题讨论】:
-
为什么要手动加载它而不是使用
TemplateResolver或注入它(使用@Resource("classpath:email-templates/html-email.html"),会很快失败)?