记录springboot在k8s下无法读取文件问题

//加载配置文件

File file = ResourceUtils.getFile("classpath:/template/job.yaml");

/对象映射

V1Job v1Job = (V1Job) Yaml.load(file);

开发的时候使用上面的方法可以读取文件数据,但是部署到k8s容器中之后,读取文件出现报错,找不到文件。于是改成了下面的写法:

复制代码
//加载配置文件
InputStream is = this.getClass().getResourceAsStream("/template/job.yaml");
//ClassPathResource resource = new ClassPathResource("/job.yaml");
File file = new File("/template/job.yaml");
FileUtils.copyInputStreamToFile(is,file);

//对象映射
V1Job v1Job = (V1Job) Yaml.load(file);

成功读取文件数据。上述两种代码在window下都可以读取。

相关推荐
苍何3 分钟前
一手实测 Claude Fable 5,手搓了个 Obsidian 的 Codex 插件
后端
zfoo-framework7 分钟前
[修改代码使用]codex官方app中使用中转(不需要cc-switch) 1.config.toml 2.sk方式登录
java
逍遥德27 分钟前
MQTT教程详解-05.SpringBoot集成mqtt client 性能分析
java·spring boot·spring·mt
云烟成雨TD31 分钟前
Spring AI 1.x 系列【54】Retry 机制分析
java·人工智能·spring
weixin_5231853234 分钟前
Collections.unmodifiableMap详解:真的不可修改吗?
java·linux·前端
点燃大海35 分钟前
SpringAI构建智能体
java·spring boot·spring·springai智能体
xier_ran37 分钟前
【infra之路】02_RadixAttention与KV_Cache管理
java·spring boot·spring
swipe44 分钟前
做多轮对话 Agent,为什么我建议把短期记忆放到 Redis
后端·面试·llm
黑马师兄1 小时前
RAG混合检索深度解析:让AI真正找到你要的内容
java·人工智能·ai·agent·rag·ai-native
码客日记1 小时前
Spring Boot 配置文件敏感信息加密(Jasypt 企业级完整方案)
java·spring boot·git