作者:核能裸麦_536 | 来源:互联网 | 2024-10-31 08:41
在SpringBoot多模块Maven项目中,经常会遇到一个启动模块无法访问其他模块中的静态资源的问题。本文首先详细描述了该问题的具体表现,然后从配置文件入手,探讨了可能的原因,并提出了一种通过调整`application.yaml`配置来解决这一问题的有效方法。此外,还介绍了如何通过优化项目结构和使用SpringBoot的静态资源路径映射功能,进一步提高资源引用的灵活性和可靠性。
一.问题描述:
在开发一个springboot的maven工程时,发现一个启动应用模块找不到另一个模块的静态资源

二问题分析:
我最开始想到是在application.yaml配置文件中进行静态资源路径配置:

但是没有效果,后来又想是不是application.java启动类没有扫描到该包:

还是不行,最后想到可能是application.class启动类的工作环境没有设置。
三.问题解决:
点击启动类:

进行编辑:

修改工作环境值:

四.完成!!!