Dynamic enumeration management method based on micro-service architecture
Through the dynamic enumeration management method based on the microservice architecture, the problems of cumbersome management and inflexible updates of traditional enumeration types are solved, and the flexibility and modular design of enumeration are realized, which improves the maintenance of the system and the accuracy of API documents.
Patent Information
- Application Number
- CN202510390185.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-31
- Publication Date
- 2025-07-01
AI Technical Summary
Traditional enumeration types are cumbersome in software development, error-prone, inflexible updates, difficult to automatically generate API documents, and poor enumeration sharing and real-time synchronization.
Based on the microservice architecture, dynamic enumeration entity class objects are defined, database interaction processors and interceptors are built, custom annotation and aspect processing classes are created, and dynamic enumeration management is realized through timed updates and annotation applications.
It realizes flexible updates and modular design of enumerations, reduces coupling, improves system maintenance and API documents accuracy, and supports dynamic updates and automated document generation.
Smart Images

Figure CN120233992A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of dynamic enumeration management, and particularly to a dynamic enumeration management method based on a microservices architecture. Background Art
[0002] In modern software development processes, enumeration types are widely used to represent finite and fixed sets of constants. Developers need to write enumeration classes, define the values and descriptions of the enumerations, and then use these enumeration classes in business logic to represent the specific meanings of attributes. However, traditional enumeration types have the following disadvantages:
[0003] (1) The process of manually defining enumeration classes is cumbersome and error-prone. Especially in large projects, the management and maintenance workload of enumeration classes is relatively large;
[0004] (2) After the enumeration class is defined, when it is necessary to modify the value or description information of the enumeration, the code must be manually modified and the project must be recompiled and deployed. This update and configuration method is not flexible enough;
[0005] (3) The values and description information of the enumeration are usually scattered in the code, making it difficult to automatically generate API documents, which affects the accuracy and readability of the API documents;
[0006] (4) The sharing and real-time synchronization problems of enumerations between multiple business systems in an enterprise cannot be solved;
[0007] Therefore, it is of great significance to design a management method that can dynamically update and generate enumeration types. Summary of the Invention
[0008] The purpose of the present invention is to provide a dynamic enumeration management method based on a microservices architecture to overcome the above-mentioned defects in the prior art.
[0009] The dynamic enumeration management method based on a microservices architecture specifically includes the following steps:
[0010] S1. Define a dynamic enumeration entity class object: Define an entity class object for dynamic enumeration, including the enumeration type type, the code value code of the enumeration, and the description information desc, to form the structure and attributes of the dynamic enumeration;
[0011] S2. Build a database interaction processor and an interceptor: When querying data from the database, convert the corresponding code value code into the required enumeration object;
[0012] S3. Create a custom annotation for operating on enumerations: Create a custom annotation for operating on dynamic enumerations;
[0013] S4. Annotation defines the specific operation logic: Create corresponding aspect processing classes for dynamic enumeration annotations, which encapsulate the actual operation logic for performing dynamic enumeration management operations;
[0014] S5. Create a link class and a factory class: Create a link class between the operation annotation and the corresponding aspect processing class to execute the corresponding methods of the operation annotation and the aspect processing class. At the same time, create a factory class to create a proxy class for the dynamic enumeration object and inject relevant configuration information into the proxy class;
[0015] S6. Subscribe to system enumerations and update the database regularly: Each business system needs to write a scheduled task to pull the latest enumeration object list regularly, and then update the enumeration list within the system when the project starts to ensure the synchronization and real-time nature of enumeration subscription;
[0016] S7. Introduce the dependency of the dynamic enumeration component in the system: Introduce the dynamic enumeration management module as a dependency in the pom file of the system that needs to use dynamic enumeration management, and trigger the operations of dynamic enumeration by adding annotations in the business code;
[0017] S8. Add configuration to the yml file: Used to inject custom Mybatis processors and interceptors;
[0018] S9. Application of custom annotations: During serialization and deserialization, add annotations to the enumeration fields of relevant DTO objects and mark the enumeration type code.
[0019] Preferably, the entity class objects in step S1 mainly include three categories: CommonEnum, CommonEnumCode, and CommonEnumDesc, corresponding to three types of interactions with the front end, namely the enumeration class object, the code value of the enumeration, and the description of the enumeration. Each enumeration corresponds to a unique typeCode, so only the typeCode and code can uniquely identify an enumeration item.
[0020] Preferably, the specific logic implemented in step S3 is to pass in the typeCode corresponding to the enumeration in the annotation, read the field value according to the annotation reflection during serialization and deserialization, create an enumeration object by EnumGenerator, and fill the attributes according to the field value and typeCode.
[0021] Preferably, the operation logic in step S4 includes reading, adding, modifying, and deleting of enumerations.
[0022] Preferably, in step S9, the enumerated type code typeCode needs to be defined in the business system. The enumerated type needs to be defined as a basic enumerated object type, such as CommonEnum, CommonEnumDesc, and CommonEnumCode.
[0023] The beneficial effects achieved by the present invention are as follows:
[0024] 1. Flexibility: Dynamic enumeration allows the code values and descriptions of the enumeration to be updated at runtime without recompiling and redeploying the system. The business system can dynamically adjust the enumerated type according to actual needs to adapt to changing business requirements.
[0025] 2. Modularity: The dynamic enumeration function is encapsulated into an independent common module, and other business systems can use it by introducing relevant dependencies. This modular design improves the code reusability and maintainability and reduces repetitive development work.
[0026] 3. Maintainability: The dynamic enumeration system makes the system maintenance more efficient by centrally managing and updating the enumeration data. When repairing or updating the module, only one place needs to be modified, and all systems depending on this module will automatically obtain the update.
[0027] 4. Dynamic update: It supports pulling and updating the latest enumeration set regularly through a scheduled task to ensure that the data in the system remains up-to-date. This dynamic update mechanism can cope with the rapid changes in business requirements and maintain the real-time nature of the data.
[0028] 5. Simplify serialization and deserialization: Support for serialization and deserialization of single enumerations and enumeration lists through annotations simplifies the processing during data transmission. Different types of serialization requirements (such as enumeration objects, descriptions, and encodings) can be flexibly handled through annotations, improving the convenience of data exchange.
[0029] 6. Reduce coupling: Separate the enumeration-related logic from the business logic to reduce the coupling between parts of the system, improving the flexibility and scalability of the system. The modular design and dynamic update mechanism reduce the dependence of the business logic on the enumeration implementation.
[0030] 7. Automatic documentation generation: Integrating the Swagger documentation generation tool, our solution can automatically identify the attributes of the enumerated type and generate corresponding description information based on the dynamic enumeration configuration information, thus improving the accuracy and readability of the API documentation. Developers can more easily understand and use the API interface. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 is a flowchart of the present invention. DETAILED DESCRIPTION OF THE INVENTION
[0032] The following will, with reference to the accompanying drawings, further elaborate on the specific implementation of the present invention through the description of embodiments, so as to help those skilled in the art have a more complete, accurate, and in-depth understanding of the concept and technical solution of the present invention.
[0033] As Figure 1 shown, the present invention provides a dynamic enumeration management method based on a microservices architecture, and this process is applicable to the dynamic management of enumerations in Spring Boot projects. It specifically includes the following steps:
[0034] I. Develop a dynamic enumeration common module (common component)
[0035] (1) Define dynamic enumeration entity class objects: Define entity class objects for dynamic enumerations, including the enumeration type type, the code value code of the enumeration, and the description information desc, which constitute the structure and attributes of the dynamic enumeration; the entity class objects mainly include three categories: CommonEnum, CommonEnumCode, and CommonEnumDesc, corresponding to three types of interactions with the front end, namely, the enumeration class object, the code value of the enumeration, and the description of the enumeration. In our system, each enumeration corresponds to a unique typeCode. Therefore, only the typeCode and code can uniquely identify an enumeration item.
[0036] (2) Set up a database interaction processor and an interceptor:
[0037] Since what is generally stored in the database is the code value corresponding to the enumeration. Therefore, when querying data from the database, it is necessary to convert the corresponding code value code into the enumeration object we need.
[0038] CommonCodeHandler / CommonDescHandler: The processor is used to convert between the numerical type in the database and the CommonEnumCode / CommonEnumDesc entity objects: In database queries, initialize the code value attribute in the database as the entity object of the dynamic enumeration.
[0039] CommonEnumInterceptor: Intercept data when the query method is executed, and fill in the desc and type attributes of the enumeration.
[0040] Actual use: It is necessary to add the @EnumType annotation to the enumeration field of the corresponding DO object in the business system to mark the typeCode of the enumeration. Intercept through the annotation, etc. in the query method by the underlying processor, and perform mutual conversion of the data.
[0041] (3) Create custom annotations for operation enums: Create custom annotations for dynamic operation enums, such as @DynamicEnum, which is used to identify enum fields that need to be dynamically managed; annotations such as @DeserilizeEnum and @DeserilizeEnumCodeList are used to serialize single enums and enum list objects; the specific implementation logic is to pass in the typeCode corresponding to the enum in the annotation, and during serialization and deserialization, read the field value according to the annotation reflection, create a new enum object by EnumGenerator, and fill the attributes according to the field value and typeCode;
[0042] (4) Define specific operation logic for the annotations: Create corresponding aspect processing classes for dynamic enum annotations, and these classes encapsulate the logic for actually performing dynamic enum management operations, including reading, adding, modifying, and deleting enums, etc.
[0043] (5) Create a binding class and a factory class: Create a binding class between the operation annotation and the corresponding aspect processing class, which is used to execute the corresponding methods of the operation annotation and the aspect processing class. At the same time, create a factory class, which is used to create a proxy class for the dynamic enum object and inject relevant configuration information into the proxy class.
[0044] II. Application in the business system
[0045] First, subscribe to the enums of this system in the code value system and update the database through a scheduled task;
[0046] Each business system needs to write a scheduled task to pull the latest enum object list regularly, and then update the enum list within the system when the project starts to ensure the synchronization and real-time nature of enum subscription;
[0047] Introduce the dependency of the dynamic enum component into the system:
[0048] Introduce the dynamic enum management module as a dependency in the pom file of the system that needs to use dynamic enum management, and trigger the operations of the dynamic enum by adding annotations in the business code;
[0049] Add configuration to the yml file:
[0050] It is used to inject custom Mybatis processors and interceptors.
[0051] (4) Application of custom annotations
[0052] During the serialization and deserialization process, it is necessary to add annotations to the enumeration fields of the relevant DTO objects and mark the enumeration type code; among them, the enumeration type code typeCode needs to be defined in the business system, and the enumeration type needs to be defined as a basic enumeration object type, such as CommonEnum, CommonEnumDesc, CommonEnumCode;
[0053] The differences among the three are as follows:
[0054] The CommonEnum type indicates that what we return to the front end is an enumeration object;
[0055] The CommonEnumDesc type indicates that what is returned to the front end is the description of the enumeration;
[0056] The CommonEnumCode type indicates that what is returned to the front end is the code of the enumeration;
[0057] By integrating the Swagger document generation tool, the automatic description and generation of the enumeration type and the values of the enumeration are realized. When generating the API document, the attributes of the enumeration type are automatically recognized, and the corresponding description information is generated according to the dynamic enumeration configuration information, improving the accuracy and readability of the API document.
[0058] To sum up, our technical solution solves the problems existing in the traditional enumeration implementation method by introducing key technical points such as dynamic enumeration configuration and management mechanism, interceptor and aspect processing, and Swagger document generation, improves the management and use efficiency of the enumeration, and at the same time enhances the flexibility and maintainability of the enumeration use.
[0059] The above-described embodiments of the present invention do not constitute a limitation on the protection scope of the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the claims of the present invention.
Claims
1. A dynamic enumeration management method based on microservice architecture, characterized by: The specific steps include: S1. Define dynamic enumeration entity class object: define the entity class object of dynamic enumeration, including enumeration type type, enumeration code value code and description information desc, which constitute the structure and attributes of dynamic enumeration; S2. Build a database interaction processor and interceptor: When querying data from the database, convert the corresponding code value code into the required enumeration object; S3. Create custom annotations for operation enumeration: Create custom annotations for dynamic enumeration of operations; S4. Annotation definition of specific operation logic: Create corresponding aspect processing classes for dynamic enumeration annotations. These classes encapsulate the actual execution of dynamic enumeration management operation logic; S5. Create a link class and a factory class: Create a link class between the operation annotation and the corresponding aspect processing class to execute the corresponding methods of the operation annotation and the aspect processing class. At the same time, create a factory class to create a proxy class for the dynamic enumeration object and inject relevant configuration information into the proxy class; S6. Subscription system enumeration and scheduled update storage: Each business system needs to write a scheduled task to regularly pull the latest enumeration object list, and then update the enumeration list in the system when the project starts to ensure the synchronization and real-time nature of the enumeration subscription; S7. Introduce the dependency of dynamic enumeration components into the system: Introduce the dynamic enumeration management module as a dependency in the pom file of the system that needs to use dynamic enumeration management, and trigger the dynamic enumeration operation by adding annotations to the business code; S8. Add configuration in yml file: used to inject custom Mybatis processors and interceptors; S9. Custom annotation application: During serialization and deserialization, add annotations to the enumeration fields of related DTO objects and mark the enumeration type encoding.
2. According to the dynamic enumeration management method based on microservice architecture according to claim 1, it is characterized in that: The entity class objects in step S1 mainly include three categories: CommonEnum, CommonEnumCode, and CommonEnumDesc, which correspond to the three types of interactions with the front end, namely enumeration class objects, enumeration code values, and enumeration descriptions. Each enumeration corresponds to a unique typeCode, so only typeCode and code are needed to uniquely identify an enumeration item.
3. The dynamic enumeration management method based on microservice architecture according to claim 1 is characterized in that: The specific logic implemented in step S3 is to pass the typeCode corresponding to the enumeration in the annotation, read the field value according to the annotation reflection during the serialization and deserialization process, create a new enumeration object by EnumGenerator, and fill in the attributes according to the field value and typeCode.
4. The dynamic enumeration management method based on microservice architecture according to claim 1 is characterized in that: The operation logic in step S4 includes enumerated reading, adding, modifying and deleting.
5. The dynamic enumeration management method based on microservice architecture according to claim 1 is characterized in that: In step S9, the enumeration type code typeCode needs to be defined in the business system, and the enumeration type needs to be defined as a basic enumeration object type, such as CommonEnum, CommonEnumDesc, and CommonEnumCode.