服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Java教程 - SpringBoot 分模块开发的操作方法

SpringBoot 分模块开发的操作方法

2022-11-02 09:56好大一只鸡 Java教程

这篇文章主要介绍了SpringBoot 分模块开发的操作方法,通过在原项目新增一个maven模块,本文通过示例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

1、在原项目新增一个maven模块

SpringBoot 分模块开发的操作方法

选 maven ,不要选 spring initializr不然会覆盖掉原项目

SpringBoot 分模块开发的操作方法

2、新增的maven模块会出现在项目中,选配置pom文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?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、在父项目POM中加上新增模块的配置

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
       <!-- 通用工具-->
        <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、在主启动模块中引用模块

?
1
2
3
4
5
6
7
8
9
10
11
12
    <!-- 代码生成-->
    <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、在主模块中配置SpringBoot的包扫描,使Controller可以用起来

?
1
2
3
4
5
6
7
8
@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);

到此这篇关于SpringBoot 分模块开发的文章就介绍到这了,更多相关SpringBoot 分模块开发内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/stwuyiyu/article/details/123866999?

延伸 · 阅读

精彩推荐