温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

SpringBoot分模块怎么开发

发布时间:2022-04-02 11:09:18 来源:亿速云 阅读:275 作者:iii 栏目:开发技术

这篇文章主要介绍“SpringBoot分模块怎么开发”,在日常操作中,相信很多人在SpringBoot分模块怎么开发问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”SpringBoot分模块怎么开发”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

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

SpringBoot分模块怎么开发

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

SpringBoot分模块怎么开发

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

<?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中加上新增模块的配置

           <!-- 通用工具-->
            <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、在主启动模块中引用模块

        <!-- 代码生成-->
        <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可以用起来

@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分模块怎么开发”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI