Spring Boot 2.5.15 多模块项目实战:RuoYi-Vue 新增业务模块的 4 处关键配置

📅 2026/7/10 1:51:48
Spring Boot 2.5.15 多模块项目实战:RuoYi-Vue 新增业务模块的 4 处关键配置
Spring Boot 2.5.15 多模块项目实战RuoYi-Vue 新增业务模块的 4 处关键配置在基于 Spring Boot 的多模块项目中新增业务模块是一个常见但容易踩坑的操作。本文将以 RuoYi-Vue 框架为例深入解析新增业务模块时需要关注的 4 个关键配置点帮助开发者避开常见陷阱。1. 父模块 pom.xml 的聚合配置多模块项目的核心在于父 pom 的聚合管理。在 RuoYi-Vue 中新增模块时首先需要在父 pom.xml 中添加子模块声明!-- 在 modules 节点中添加新模块 -- modules moduleruoyi-admin/module moduleruoyi-common/module moduleruoyi-system/module !-- 新增的图集管理模块 -- moduleruoyi-img/module /modules同时需要确保父 pom 中已包含 Spring Boot 的依赖管理parent groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-parent/artifactId version2.5.15/version relativePath/ /parent提示父 pom 中的dependencyManagement节点可以统一管理各子模块的依赖版本避免版本冲突。2. 子模块间的依赖关系配置新增模块通常需要与其他模块建立依赖关系。在 ruoyi-img 模块的 pom.xml 中需要明确定义这些依赖dependencies !-- 依赖common模块 -- dependency groupIdcom.ruoyi/groupId artifactIdruoyi-common/artifactId version${project.version}/version /dependency !-- 必要的Spring Boot starter -- dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-web/artifactId /dependency /dependencies模块依赖关系建议遵循以下原则单向依赖避免循环依赖保持依赖关系的单向流动最小化原则只引入必要的依赖版本一致通过父 pom 统一管理依赖版本3. 包扫描路径的扩展配置新增模块后最常见的 404 问题往往源于包扫描配置。需要在启动类上明确指定新增模块的包路径SpringBootApplication(exclude { DataSourceAutoConfiguration.class }, scanBasePackages { com.ruoyi.common, com.ruoyi.system, com.ruoyi.img // 新增模块的包路径 }) public class RuoYiApplication { public static void main(String[] args) { SpringApplication.run(RuoYiApplication.class, args); } }包扫描配置需要注意通配符使用com.ruoyi.*可以简化配置但可能扫描到不需要的包性能考量扫描范围越大应用启动越慢模块化设计良好的包结构能减少扫描范围4. 安全配置的权限调整在 RuoYi-Vue 的权限体系中新增模块的接口需要配置访问权限。修改 SecurityConfig 类Override protected void configure(HttpSecurity httpSecurity) throws Exception { httpSecurity .authorizeRequests() .antMatchers( /swagger-ui.html, /image/** // 新增模块的接口路径 ).permitAll() .anyRequest().authenticated(); }安全配置建议开发阶段可以临时开放接口权限生产环境必须配置精确的权限控制RBAC 集成最终应该通过角色权限系统管理常见问题排查表问题现象可能原因解决方案接口返回404包扫描未配置检查启动类scanBasePackages依赖类找不到模块依赖未添加检查子模块pom.xml依赖启动时报错版本冲突统一父pom中的依赖版本权限校验失败安全配置未更新检查SecurityConfig配置模块化开发的最佳实践分层清晰保持各模块职责单一接口契约模块间通过明确定义的接口交互独立测试每个模块应该可以独立编译和测试版本管理使用父pom统一管理依赖版本# 推荐的多模块构建命令 mvn clean install -pl ruoyi-img -am注意-pl指定模块-am会自动构建依赖的模块通过以上4个关键配置点的正确设置可以确保新增模块顺利集成到现有项目中。在实际开发中建议先搭建最小可用模块再逐步添加功能这样可以及早发现和解决集成问题。