错误原因
其中getReader(@NotNull String resource, java.nio.charset.Charset charset)
对resource的位置先进行绝对路径判断,如果没找到会进行相对路径查找。

(是kotlin格式写的)
ResourceUtil.getReader(
"/${
if (tplName.toLowerCase().endsWith(".sql")) {
tplName
} else {
tplName + ".sql"
}
}", Charsets.UTF_8
).readText()
我应该是相对路径吧…但是,系统报错:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘cronComponent’:
Invocation of init method failed; nested exception is cn.hutool.core.io.IORuntimeException:
FileNotFoundException: F:\mxsql1.sql (系统找不到指定的文件。)
也就是说我的路径错误。
解决办法
查了很多资料,找到了其中一个好用的解决方法,加入classpath.
ResourceUtil.getReader(
"classpath:/${
if (tplName.toLowerCase().endsWith(".sql")) {
tplName
} else {
tplName + ".sql"
}
}", Charsets.UTF_8
).readText()
疑问和思考
我用的是springboot和kotlin,按理说springboot会自动查找到resource下面的文件,但是我报错是直接查的绝对路径(项目在F盘下)。需要找到原因,然后把路径改到resource下。
当天(2021/8/19)更新:不用添加classpath,将函数内的“/”去掉后就可以运行了,郁闷。。。
1020

被折叠的 条评论
为什么被折叠?



