How to Add a New Business Submodule in Ruoyi Microservice and Generate CRUD Code

This guide walks you through adding a new business module to a locally‑deployed Ruoyi microservice project, configuring Maven and Nacos, generating backend CRUD code, integrating the frontend, and performing end‑to‑end testing to ensure the new service runs correctly alongside existing modules.

The Dominant Programmer
The Dominant Programmer
The Dominant Programmer
How to Add a New Business Submodule in Ruoyi Microservice and Generate CRUD Code

Adding a Business Module and Configuring Maven

In the ruoyi-modules directory, right‑click and select New → Module . Name the new module ruoyi-fzyscontrol to keep the naming style consistent with existing modules. After confirming, the module appears as a sub‑module of ruoyi-modules. Open the parent pom.xml and copy the dependencies and build sections from ruoyi-modules-system into the new module’s pom.xml.

<dependencies>
    <!-- Spring Cloud Alibaba Nacos Discovery -->
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
    </dependency>
    <!-- Spring Cloud Alibaba Nacos Config -->
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
    </dependency>
    <!-- Spring Cloud Alibaba Sentinel -->
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
    </dependency>
    <!-- Spring Boot Actuator -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <!-- Swagger UI -->
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>${swagger.fox.version}</version>
    </dependency>
    <!-- MySQL Connector -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <!-- Ruoyi Common Libraries -->
    <dependency>
        <groupId>com.ruoyi</groupId>
        <artifactId>ruoyi-common-security</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>

Create the package com.ruoyi.fzyscontrol under the new module and copy the startup class from the existing system module, renaming it appropriately.

Configuring Nacos and Gateway

Copy the ruoyi-system-dev.yml configuration from Nacos, clone it, and rename the Data Id to ruoyi-fzyscontrol-dev.yml . Update the package scan path to com.ruoyi.fzyscontrol and adjust the mapper location pattern to classpath:mapper/**&#47;*.xml . Add a new entry in ruoyi-gateway-dev.yml : <code>- id: ruoyi-fzyscontrol uri: lb://ruoyi-fzyscontrol predicates: - Path=/fzyscontrol/** filters: - StripPrefix=1</code> Similarly, add the service definition to the system gateway configuration so that the new module is discoverable. Starting the Services Start the services in the following order: ruoyi-gateway , ruoyi-auth , ruoyi-system , ruoyi-gen , and finally the newly created ruoyi-fzyscontrol . Verify that five services appear in the Nacos service list. Generating Backend CRUD Code Log into the Ruoyi UI, navigate to System Tools → Code Generation → Import , and import the table created for the new business feature. Adjust the generated code settings so that the package name matches com.ruoyi.fzyscontrol and includes the additional layer for “运行调度管理”. After submitting, download and unzip the generated code archive, then copy the backend files into the corresponding directories of the new module. Integrating the Frontend In the ruoyi-ui project, run npm install and change the development port from 80 to 90 in vue.config.js . Update the proxy target to match the gateway port (changed from 8080 to 8888 ) so that API calls are correctly routed. <code>npm install npm run dev</code> Copy the generated Vue files into the appropriate api and views folders, ensuring the import paths and menu button routes align with the backend controller URLs. Front‑Back End Coordination If the frontend request URL (e.g., /runcontrolmange/signallightcontrol/list ) does not match the backend controller mapping, adjust the controller’s @RequestMapping path or add the gateway prefix defined in Nacos to the frontend request URL. After correcting the prefixes, the menu becomes accessible and the new service functions as expected. Summary of Steps Create a new module ruoyi-fzyscontrol under ruoyi-modules . Copy Maven dependencies and build sections from an existing module. Create package com.ruoyi.fzyscontrol and copy the startup class. Clone and modify Nacos configuration files for the new module. Add gateway routing entries for the new service. Start all services in the correct order and verify registration in Nacos. Use Ruoyi’s code‑generation tool to generate CRUD code for the new table. Integrate generated backend code into the module and generated Vue code into the UI. Adjust frontend proxy and request URLs to include the gateway prefix. Test the end‑to‑end flow to ensure the new business feature works.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

code generationNacoscrudSpring CloudFrontend IntegrationRuoYi
The Dominant Programmer
Written by

The Dominant Programmer

Resources and tutorials for programmers' advanced learning journey. Advanced tracks in Java, Python, and C#. Blog: https://blog.csdn.net/badao_liumang_qizhi

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.