


How to centralize the Entity, Mapper, and Service of the business module into the Common module in Spring Cloud Alibaba?
Apr 19, 2025 pm 06:30 PMBest practices for centrally managing public modules Entity, Mapper, and Service in Spring Cloud Alibaba
When building a microservice architecture using Spring Cloud Alibaba, it is crucial to organize your code structure properly. This article discusses how to integrate the Entity, Mapper, and Service components of multiple business modules into a common module (Common module), and resolve possible conflicts and problems, ultimately improving code reusability and maintainability.
Project structure:
Suppose the project contains the following modules:
- common module: includes Entity, Mapper, Service interface and implementation classes, database connection configuration, unified exception handling, Redis JSON serialization, unified response result encapsulation, Swagger configuration, MyBatis Plus configuration, CORS configuration and other common components.
- Merchant module (merchant terminal): contains controller, calls the Service in the common module to process business logic and provides an API interface to the outside world.
- supply module (supplier): Similar to the merchant module, it contains controller and business logic, and also relies on the common module.
Problems and solutions:
When starting the merchant module, a javax.management.InstanceAlreadyExistsException
error appears, which is usually related to Spring Boot Admin conflicts, and may also be related to incorrect package scanning configurations. The solution is as follows:
-
Precise package scanning configuration: In the startup class of each business module (merchant and supply), use
@ComponentScan
to accurately specify the package path to scan. Avoid using wildcards*
, only scan the controls of the business module itself, and rely on components in the common module. For example, the start class of the merchant module:@SpringBootApplication @ComponentScan(basePackages = "com.quanneng.merchant") // Scan only the components under the merchant module @MapperScan("com.quanneng.common.mapper") // Scan the mapper interface separately public class MerchantApiApplication { // ... }
Avoid Spring Boot Admin conflicts: If Spring Boot Admin is used, make sure it is configured correctly and does not conflict with other components. Check the configuration of Spring Boot Admin to make sure the name of the application it monitors is unique. If the problem persists, you can temporarily disable Spring Boot Admin to check whether it is a conflict caused by it.
Mapper interface scanning: Use the
@MapperScan
annotation to scan the Mapper interface under the common module separately to avoid conflicts with the Mapper interface of other modules. Ensure that the package path specified by@MapperScan
is accurate.Dependency management of public components: Ensure that all public components dependencies in common modules are correctly declared and that the version is compatible with other modules.
Modular design: Design the common module as a separate module and package it into a Spring Boot Starter. In this way, other modules only need to rely on this Starter to easily use the components in the common module, avoiding the complexity of package scanning configuration.
Improvement suggestions:
- Use Spring Boot Starter: Package common modules into a Spring Boot Starter to simplify dependency management and configuration.
- Unified exception handling: Implement a unified exception handling mechanism in common module and use it in all modules.
- Unified response results: Define a unified response result format in the common module to improve the consistency of the API interface.
- Modular principle: Follow the modular design principle, separate public components from business components, and improve the maintainability and reusability of code.
Through the above steps, you can effectively concentrate Entity, Mapper, and Service components into the common module and avoid potential conflicts. Accurate package scanning configuration and modular design are key to solving such problems. If you still encounter problems, please check the log information to find out the specific cause of the error.
The above is the detailed content of How to centralize the Entity, Mapper, and Service of the business module into the Common module in Spring Cloud Alibaba?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The garbled problem in Java Chinese is mainly caused by inconsistent character encoding. The repair method includes ensuring the consistency of the system encoding and correctly handling encoding conversion. 1.Use UTF-8 encoding uniformly from files to databases and programs. 2. Clearly specify the encoding when reading the file, such as using BufferedReader and InputStreamReader. 3. Set the database character set, such as MySQL using the ALTERDATABASE statement. 4. Set Content-Type to text/html;charset=UTF-8 in HTTP requests and responses. 5. Pay attention to encoding consistency, conversion and debugging skills to ensure the correct processing of data.

For good reason, Blockdag focuses on buyer interests. Blockdag has raised an astonishing $265 million in 28 batches of its pre-sales As 2025 approaches, investors are steadily accumulating high-potential crypto projects. Whether it’s low-cost pre-sale coins that offer a lot of upside, or a blue chip network that prepares for critical upgrades, this moment provides a unique entry point. From fast scalability to flexible modular blockchain architecture, these four outstanding names have attracted attention throughout the market. Analysts and early adopters are watching closely, calling them the best crypto coins to buy short-term gains and long-term value now. 1. BlockDag (BDAG): 7 days left

Linux system restricts user resources through the ulimit command to prevent excessive use of resources. 1.ulimit is a built-in shell command that can limit the number of file descriptors (-n), memory size (-v), thread count (-u), etc., which are divided into soft limit (current effective value) and hard limit (maximum upper limit). 2. Use the ulimit command directly for temporary modification, such as ulimit-n2048, but it is only valid for the current session. 3. For permanent effect, you need to modify /etc/security/limits.conf and PAM configuration files, and add sessionrequiredpam_limits.so. 4. The systemd service needs to set Lim in the unit file

There are three ways to install the NumPy library: 1. Use pip to install: pipinstallnumpy, which is simple but may encounter permissions or network problems; 2. Use conda to install: condainstallnumpy, which is suitable for Anaconda environment, and automatically resolves dependencies; 3. Install: gitclone from source code and compile, which is suitable for special needs but complicated processes.

ServiceWorker implements offline caching by intercepting network requests and providing pre-cache resources. The specific steps include: 1) Register ServiceWorker and check browser support; 2) Define cache policies and pre-cache resources in the sw.js file; 3) Pre-cache resources using install event and decide to obtain resources from the cache or network in the fetch event; 4) Pay attention to version control, cache policy selection and debugging skills; 5) Optimize cache size, process dynamic content, and ensure that scripts are loaded through HTTPS.

Deploying and tuning Jenkins on Debian is a process involving multiple steps, including installation, configuration, plug-in management, and performance optimization. Here is a detailed guide to help you achieve efficient Jenkins deployment. Installing Jenkins First, make sure your system has a Java environment installed. Jenkins requires a Java runtime environment (JRE) to run properly. sudoaptupdatesudoaptininstallopenjdk-11-jdk Verify that Java installation is successful: java-version Next, add J

The reasons and solutions for the MySQL service cannot be started include: 1. Check the error log and find key error information, such as the port is occupied, and terminate the occupied process through the netstat-ano command. 2. Fix or replace corrupt configuration files, using default configuration or official examples. 3. Ensure that the service is running as a user with sufficient permissions and modify the service login account. 4. Consider upgrading or downgrading the MySQL version, and install the latest stable version after backing up the data. 5. Check the firewall settings to ensure that the MySQL port is allowed to pass. 6. Check the system update log and deal with compatibility issues with dependency libraries or system components. 7. Ensure sufficient hard disk space and avoid insufficient data directory space. 8. If all the above methods are ineffective, seek professional help, such as M

If the iPhone cannot be turned on, you can solve the following methods: 1. Forced restart: For iPhone 8 and later models, quickly press and release the volume up key, then quickly press and release the volume down key, and finally press and hold the side button until you see the Apple logo. 2. Check the battery level: Connect the phone to the charger for at least 15 minutes, and then try to turn it on. 3. Contact Apple customer service or go to Apple's authorized service center for repairs. 4. Use recovery mode: Connect your computer, use iTunes or Finder, press and hold the side button until the logo connected to iTunes appears, and select "Recover". 5. Check for physical damage: Check for cracks, depressions or other damage to the phone. If so, it is recommended to go to the maintenance center for treatment as soon as possible.
