Home >Java >javaTutorial >How to develop SpringBoot sub-modules
1. Add a maven module to the original project
Select maven, do not select spring initializr, otherwise the original project will be overwritten
2. The new maven module will appear in the project, select the configuration pom file
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> //各个子项目,需要添加对parent 的依赖 <artifactId>ruoyi</artifactId> //parent项目中不存放任何代码,只是管理多个项目之间公共的依赖,即项目最外部的那个POM <groupId>com.ruoyi</groupId> <version>3.8.1</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>stone</artifactId> //模块名称 <dependencies> <!-- 通用工具--> //引用其它模块或组件,开发时用的到 <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common</artifactId> </dependency> </dependencies> </project>
3. Add the configuration of the new module to the parent project POM
<!-- 通用工具--> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common</artifactId> <version>${ruoyi.version}</version> </dependency> <!-- stone--> //这里添加新增的模块 <artifactId>stone</artifactId> </dependencies> </dependencyManagement> <modules> <module>ruoyi-admin</module> <module>ruoyi-framework</module> <module>ruoyi-system</module> <module>ruoyi-quartz</module> <module>ruoyi-generator</module> <module>ruoyi-common</module> <module>stone</module> //这里注明引入的是模块 </modules>
4. Reference the module in the main startup module
<!-- 代码生成--> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-generator</artifactId> </dependency> <!-- stone--> //主启动模块这里也加上去 <dependency> <groupId>com.ruoyi</groupId> <artifactId>stone</artifactId> <version>3.8.1</version> </dependency> </dependencies>
5. Configure SpringBoot's package scanning in the main module so that the Controller can be used
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) @ComponentScan(basePackages = {"com.ruoyi.*","com.ruoyi.stone.*"}) //这里需加入包扫描,否则启用不了新增模块里面的控制器等方法 public class RuoYiApplication { public static void main(String[] args) { // System.setProperty("spring.devtools.restart.enabled", "false"); SpringApplication.run(RuoYiApplication.class, args);
The above is the detailed content of How to develop SpringBoot sub-modules. For more information, please follow other related articles on the PHP Chinese website!