RuoYi-Cloud 新建子模块注意事项 新建过程

RuoYi-Cloud 新建子模块注意事项 新建过程

📔 笔记介绍

大家好,这里是千寻简笔记,我是作者星辰,笔记内容整理并发布,内容有误请指出,笔记源码已开源,前往Gitee搜索《chihiro-notes》感谢您的观看。

作者各大平台直链: GitHub | Gitee | CSDN

后端 新建子模块

Maven多模块下新建子模块流程案例。

1、在ruoyi-modules下新建业务模块目录,例如:ruoyi-test

2、在ruoyi-test业务模块下新建pom.xml文件以及src\main\javasrc\main\resources目录。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <groupId>com.ruoyi</groupId>
        <artifactId>ruoyi-modules</artifactId>
        <version>x.x.x</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
	
    <artifactId>ruoyi-modules-test</artifactId>

    <description>
        ruoyi-modules-test系统模块
    </description>
	
    <dependencies>
    	
    	<!-- SpringCloud Alibaba Nacos -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
        
        <!-- SpringCloud Alibaba Nacos Config -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>
        
    	<!-- SpringCloud Alibaba Sentinel -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
        </dependency>
        
    	<!-- SpringBoot Actuator -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
		
        <!-- Mysql Connector -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        
        <!-- Ruoyi Common Security -->
        <dependency>
            <groupId>com.ruoyi</groupId>
            <artifactId>ruoyi-common-security</artifactId>
        </dependency>
        
        <!-- Ruoyi Common Swagger -->
        <dependency>
            <groupId>com.ruoyi</groupId>
            <artifactId>ruoyi-common-swagger</artifactId>
        </dependency>
		
		<!-- RuoYi Common Log -->
        <dependency>
            <groupId>com.ruoyi</groupId>
            <artifactId>ruoyi-common-log</artifactId>
        </dependency>
        
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
   
</project>

3、在ruoyi-modules目录下pom.xml模块节点modules添加业务模块

<module>ruoyi-test</module>

4、src/main/resources添加bootstrap.yml文件

# Tomcat
server:
  port: 9301

# Spring
spring: 
  application:
    # 应用名称
    name: ruoyi-test
  profiles:
    # 环境配置
    active: dev
  cloud:
    nacos:
      discovery:
        # 服务注册地址
        server-addr: 127.0.0.1:8848
      config:
        # 配置中心地址
        server-addr: 127.0.0.1:8848
        # 配置文件格式
        file-extension: yml
        # 共享配置
        shared-configs:
          - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

5、com.ruoyi.test包下添加启动类

package com.chihiro.table;

import com.ruoyi.common.security.annotation.EnableCustomConfig;
import com.ruoyi.common.security.annotation.EnableRyFeignClients;
import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


/**
 * 表格模块
 *
 * @author ruoyi
 */
@EnableCustomConfig
@EnableCustomSwagger2
@EnableRyFeignClients
@SpringBootApplication
public class ChihiroTableApplication
{
    public static void main(String[] args)
    {
        SpringApplication.run(ChihiroTableApplication.class, args);
        System.out.println("(♥◠‿◠)ノ゙  表格模块启动成功   ლ(´ڡ`ლ)゙  \n" +
                " .-------.       ____     __        \n" +
                " |  _ _   \\      \\   \\   /  /    \n" +
                " | ( ' )  |       \\  _. /  '       \n" +
                " |(_ o _) /        _( )_ .'         \n" +
                " | (_,_).' __  ___(_ o _)'          \n" +
                " |  |\\ \\  |  ||   |(_,_)'         \n" +
                " |  | \\ `'   /|   `-'  /           \n" +
                " |  |  \\    /  \\      /           \n" +
                " ''-'   `'-'    `-..-'              ");
    }
}


注意修改

不修改容易使404

1 添加路由

1.登录上nacos,在 配置管理->配置列表 里找到 ruoyi-gateway-dev.yml ,点击 编辑

找到 routes 节点,参考写好的路由,增加自己子模块的路由

2.把 ruoyi-system-dev.yml 克隆一份,创建自己子模块的配置文件,修改里面的配置,特别注意 mybatis 节点的修改

2 添加扫描Mapper配置

自定义包名配置

@MapperScan 怎么扫描多个包

@MapperScan({"com.myapp.**.mapper","com.ruoyi.**.mapper"})

nacos 新增一个配置文件

  • 打开http://localhost:8848/nacos
  • 点击添加

image-20221009164903658

  • 配置yml文件

image-20221009165511953

# spring配置
spring: 
  redis:
    host: localhost
    port: 6379
    password: 
  datasource: 
    # 主库数据源
    master:
      driver-class-name: com.mysql.cj.jdbc.Driver
      # url: jdbc:mysql://localhost:3306/ry-cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
      url: jdbc:mysql://localhost:3306/ry-cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
      username: root
      password: root
    # 从库数据源
    # slave:
      # url: mongodb://localhost:27017/chihiro_table
      # username: 
      # password: 
      # driver-class-name: 
# swagger配置
swagger:
  title: 代码生成接口文档
  license: Powered By ruoyi
  licenseUrl: https://ruoyi.vip
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要在 RuoYi-Cloud 中添加跨模块事务,可以按照以下步骤进行操作: 1. 首先,确保你已经将 RuoYi-Cloud 项目成功部署并运行起来。 2. 打开你的项目文件夹,在命令行中进入 RuoYi-Cloud-Admin 模块的根目录。 3. 执行以下命令,引入 Spring Cloud Alibaba 的相关依赖: ``` mvn clean install -DskipTests ``` 4. 在 RuoYi-Cloud-Admin 模块的 `pom.xml` 文件中添加以下依赖: ```xml <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-seata</artifactId> </dependency> ``` 5. 在 `application.yml` 配置文件中添加 Seata 配置: ```yaml seata: enable-auto-data-source-proxy: false application-id: ${spring.application.name} tx-service-group: my_tx_group service: vgroup-mapping: my_tx_group: "default" enable-degrade: false disable-global-transaction: false registry: type: nacos nacos: application: ${spring.application.name} server-addr: ${spring.cloud.nacos.discovery.server-addr} namespace: ${spring.cloud.nacos.discovery.namespace} ``` 6. 在 `application.yml` 配置文件中,根据你的数据库设置,配置 Seata 的数据源代理(DataSourceProxy): ```yaml spring: datasource: dynamic: primary: master strict: false datasource: master: url: jdbc:mysql://localhost:3306/ruoyi?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai username: root password: 123456 driver-class-name: com.mysql.cj.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource ... ``` 7. 在 RuoYi-Cloud-Admin 模块的启动类中,添加 `@EnableAspectJAutoProxy` 注解,开启 AOP 功能。 8. 在需要实现跨模块事务的方法上,添加 `@Transactional` 注解,标记为事务方法。 9. 重新编译和运行 RuoYi-Cloud 项目,完成跨模块事务的添加。 以上是在 RuoYi-Cloud 中添加跨模块事务的简要步骤,具体的操作细节可能会有所差异,根据你的项目实际情况进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

千寻简

感谢支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值