Public data component automatic assembly implementation method
By triggering the automatic assembly of common data components at the business logic layer, the problems of insufficient flexibility and weak uniformity under the Spring Boot framework are solved, achieving precise control and consistency management in a microservice architecture, and improving the system's flexibility and maintainability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-12
- Publication Date
- 2026-03-13
AI Technical Summary
Existing technologies under the Spring Boot framework suffer from insufficient flexibility of public data components, coarse control granularity, and weak consistency guarantees, making it difficult to achieve precise control and cross-service consistency management in a microservice architecture, resulting in high configuration complexity.
It adopts a layered architecture, and by calling the doAware() method at the Service method location in the business logic layer, it uses the AwareServiceFactory to execute the routing mechanism to achieve automatic assembly of common data components. The assembly timing is controlled by the business code, and it supports multiple data sources and dynamic service selection.
It enables flexible triggering of common data component assembly in business processes, improves control granularity and cross-service uniformity, simplifies the configuration process, and enhances the system's scalability and testability.
Smart Images

Figure CN121657973A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer software technology, and in particular to a method for automatically assembling common data components. Background Technology
[0002] In existing technologies, the Spring Boot framework implements "convention over configuration" autowiring of components through the `@EnableAutoConfiguration` annotation and the `spring.factories` configuration file, simplifying development. However, this approach has significant limitations when managing common data components (such as user information, business IDs, etc.):
[0003] Insufficient flexibility: The assembly timing is fixed by the container lifecycle and cannot be precisely triggered at specific business logic points (such as after a transaction begins or after permission verification is passed).
[0004] Coarse control granularity: Assembly methods based on classpath scanning and conditional annotations are difficult to handle complex scenarios such as multiple data sources and dynamic service selection.
[0005] Weak consistency guarantee: In a microservice architecture, it is difficult to ensure the consistency and centralized management of public data configurations across multiple services.
[0006] Disadvantages of existing technology:
[0007] 1. Limited flexibility and control granularity: Automated assembly is holistic, providing the convenience of "convention over configuration," but at the cost of not being able to perform finer-grained control. When it is necessary to use non-standard implementations for specific attributes or to perform precise control, manual configuration is often required to override automated assembly, a process that is sometimes more complex than direct manual configuration.
[0008] 2. Insufficient guarantee of public data consistency: Existing mechanisms focus more on the assembly of individual components, and have weak support for consistency management, version compatibility, and centralized configuration control of public data components across multiple services or modules. This can easily lead to differences in public data configurations between different instances in a microservice architecture.
[0009] 3. High configuration complexity: In scenarios with multiple data sources and cross-services, a large amount of manual configuration is still required. Summary of the Invention
[0010] In view of the above problems, the present invention is proposed to provide an automatic assembly method for public data components that overcomes or at least partially solves the above problems.
[0011] According to one aspect of the present invention, an automatic assembly method for public data components is provided, the method comprising:
[0012] The public data component is a layered architecture, including: presentation layer, business logic layer, public data assembly layer, data access layer, and external services / data sources;
[0013] Request entry point: The client request reaches the Controller in the presentation layer;
[0014] Business logic processing: The Controller calls the Service method of the business logic layer;
[0015] Triggering assembly: At the appropriate point in the Service method, the developer calls the doAware() method, passing in the public data object that needs to be assembled;
[0016] Factory routing: The doAware() method internally delegates to the AwareServiceFactory.execute() method;
[0017] Service execution;
[0018] Data acquisition and assembly;
[0019] Result returned: The assembled public data object is returned to the Service method to continue subsequent business logic, and finally the response is returned to the client.
[0020] Optionally, the data access layer includes: database calls, Feign client calls to remote services, or access to the cache.
[0021] Optionally, the service execution includes:
[0022] The factory uses a "dual dispatch" mechanism to find a matching ViewPropertiesAwareService implementation and calls the doAware method.
[0023] Optionally, the data acquisition and assembly specifically includes: the matching service acquires the actual data through the data access layer and assembles it into the incoming public data object.
[0024] Optionally, the automatic assembly implementation method further includes: a complete interaction from the business code calling doAware() to the completion of data assembly.
[0025] Optionally, the complete interaction from the business code calling doAware() to the completion of data assembly specifically includes:
[0026] Business calls include:
[0027] Caller: ClueFllwupRcrdTblServiceImpl;
[0028] Action: In its business method, call someBusinessObject.doAware();
[0029] someBusinessObject is a business object that implements the ViewPropertiesAware interface;
[0030] The delegation is handled by the factory, implemented by the `someBusinessObject.doAware()` method: This method is very simple to implement, usually consisting of only one line of code: `awareServiceFactory.execute(this)`;
[0031] The factory executes the routing; the internal logic of the `AwareServiceFactory.execute(ViewPropertiesAware obj)` method.
[0032] Service execution assembly logic: Implementation of the UserInfoAwareService.doAware(ViewPropertiesAwareobj) method:
[0033] Control is returned after the assembly service is completed:
[0034] ViewPropertiesAwareService->AwareServiceFactory->Business Object->Initial Business ServiceClueFllwupRcrdTblServiceImpl.
[0035] Optionally, the factory executes routing, and the internal logic of the AwareServiceFactory.execute method specifically includes:
[0036] Iterate through the service list and obtain the ViewPropertiesAwareService list maintained internally by the factory;
[0037] For each service in the list, the factory calls the accept(obj) method, passing the current business object obj as a parameter.
[0038] Execute the matching service, find the first service whose accept method returns true, and the factory calls the service's doAware(obj) method.
[0039] Optionally, the implementation method further includes: key attributes and configurability;
[0040] The `testFlag` property: `AwareServiceFactory` can contain a boolean `testFlag` property. When set to `true`, the `execute` method can skip the actual data assembly logic or return mock data.
[0041] Execution strategy: The factory supports different execution strategies.
[0042] First-match strategy: Once the first service that returns true with accept is found, execute and return immediately.
[0043] Execute all services: Execute all services that return true with accept, suitable for situations where an object needs multiple types of common data.
[0044] This invention provides a method for automatically assembling a public data component. The method includes: the public data component is a layered architecture, comprising: a presentation layer, a business logic layer, a public data assembly layer, a data access layer, and an external service / data source; request entry point: client requests arrive at the Controller in the presentation layer; business logic processing: the Controller calls the Service method in the business logic layer; triggering assembly: at an appropriate location in the Service method, the developer calls the `doAware()` method, passing in the public data object to be assembled; factory routing: the `doAware()` method internally delegates to the `AwareServiceFactory.execute()` method; service execution; data acquisition and assembly; result return: the assembled public data object is returned to the Service method to continue subsequent business logic, and finally, the response is returned to the client. This method shifts the assembly timing from container control to business code control, representing a qualitative leap. Triggering assembly like calling a regular business method integrates into the business flow and provides a strong ability to handle complex and ever-changing business scenarios.
[0045] The above description is merely an overview of the technical solution of the present invention. In order to better understand the technical means of the present invention and to implement it in accordance with the contents of the specification, and in order to make the above and other objects, features and advantages of the present invention more apparent and understandable, specific embodiments of the present invention are described below. Attached Figure Description
[0046] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0047] Figure 1A flowchart illustrating an automatic assembly method for public data components provided in an embodiment of the present invention;
[0048] Figure 2 This is a schematic diagram of the architecture for automatic assembly of public data components provided in an embodiment of the present invention;
[0049] Figure 3 This is a schematic diagram illustrating the core interfaces, class designs, and interactions provided in the embodiments of the present invention.
[0050] Figure 4 This is a sequence diagram of the core execution flow provided in the embodiments of the present invention. Detailed Implementation
[0051] Exemplary embodiments of the present disclosure will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
[0052] The terms "comprising" and "having," and any variations thereof, in the specification, embodiments, claims, and drawings of this invention are intended to cover non-exclusive inclusion, such as including a series of steps or units.
[0053] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments.
[0054] like Figure 1 As shown, an automatic assembly method for public data components includes: the public data component is a layered architecture, including: a presentation layer, a business logic layer, a public data assembly layer, a data access layer, and external services / data sources; request entry point: client requests arrive at the Controller in the presentation layer; business logic processing: the Controller calls the Service method in the business logic layer; triggering assembly: at an appropriate location in the Service method, the developer calls the doAware() method, passing in the public data object to be assembled; factory routing: the doAware() method internally delegates to the AwareServiceFactory.execute() method; service execution; data acquisition and assembly; result return: the assembled public data object is returned to the Service method to continue subsequent business logic, and finally the response is returned to the client. This shifts the assembly timing from container control to business code control, representing a qualitative leap. Triggering assembly like calling ordinary business methods integrates into the business flow and has a strong ability to handle complex and ever-changing business scenarios.
[0055] like Figure 2The architecture diagram shown illustrates a layered architecture, from top to bottom, comprising: a presentation layer (Controller), a business logic layer (Service), a common data assembly layer (the core of this invention), a data access layer (DAO / Feign Client), and external services / data sources. The core of this invention, AwareServiceFactory, and its service group are located between the business logic layer and the data access layer, acting as a dedicated data assembly middleware.
[0056] Architecture workflow:
[0057] Request entry point: The client request reaches the Controller in the presentation layer.
[0058] Business logic processing: The Controller calls the Service method of the business logic layer.
[0059] Triggering assembly: At the appropriate point in the Service method, the developer calls the doAware() method, passing in the public data object (or its identifier) to be assembled.
[0060] Factory routing: The `doAware()` method internally delegates to the `AwareServiceFactory.execute()` method. The factory becomes the central router in the assembly process.
[0061] Service execution: The factory finds the matching ViewPropertiesAwareService implementation based on the "double dispatch" mechanism and calls its doAware method.
[0062] Data Acquisition and Assembly: The matching service obtains the actual data through the data access layer (which may be a database call, a Feign client call to a remote service, or access to a cache) and assembles it into the incoming public data object.
[0063] Result returned: The assembled public data object is returned to the Service method to continue subsequent business logic, and finally the response is returned to the client.
[0064] like Figure 3 As shown, the core interfaces, class design, and interactions are illustrated in the class diagram: This diagram clearly shows the relationships between the core interfaces and classes.
[0065] The ViewPropertiesAware interface is the unified entry contract for assembly operations. It defines only one method: void doAware(). All business objects that need to assemble public data (such as a DTO or an entity) should implement this interface. Implementing this interface means that the object declares the ability "I need to be assembled".
[0066] The ViewPropertiesAwareService interface: This is the contract for the specific assembly logic. It defines two core methods:
[0067] boolean accept(ViewPropertiesAware awareObject): Service selector. Determines whether the service is willing and able to process the passed-in awarenessObject.
[0068] void doAware(ViewPropertiesAware awareObject): Assembles the executor. It contains the specific business logic, such as calling remote services, querying the database, and setting properties.
[0069] AwareServiceFactory class: The core class.
[0070] Maintain a List <viewpropertiesawareservice>The collection serves as a service registry.
[0071] Two key methods are provided:
[0072] void register(ViewPropertiesAwareService service): Used to dynamically register services with the factory.
[0073] void execute(ViewPropertiesAware awareObject): The core method for executing the assembly process.
[0074] Specific service implementation classes, such as UserInfoAwareService and BusinessIdAwareService, implement the ViewPropertiesAwareService interface and are the concrete carriers of the assembly logic.
[0075] The core execution process is as follows Figure 4 As shown,
[0076] Sequence diagram description: Figure 4 The complete interactive process, from the business code calling doAware() to the completion of data assembly, is described in detail in chronological order.
[0077] Detailed explanation of the process steps:
[0078] 4.3.1. Business Invocation
[0079] Caller: ClueFllwupRcrdTblServiceImpl (a business service implementation class)
[0080] Action: In its business method, call someBusinessObject.doAware(). someBusinessObject is a business object that implements the ViewPropertiesAware interface.
[0081] 4.3.2. Outsourced to the factory
[0082] The `someBusinessObject.doAware()` method is implemented in a very simple way, usually with only one line of code: `awareServiceFactory.execute(this)`. This indicates that the business object itself does not care how it is assembled; it simply delegates the assembly request to a specialized factory. This conforms to the "Single Responsibility Principle".
[0083] 4.3.3. Factory Execution Routing
[0084] The internal logic of the AwareServiceFactory.execute(ViewPropertiesAware obj) method:
[0085] 4.3.3.1: Traverse the service list. The factory retrieves its internally maintained list of ViewPropertiesAwareServices.
[0086] 4.3.3.2: Service Filtering (the key to double dispatch). For each service in the list, the factory calls its accept(obj) method, passing the current business object obj as the parameter.
[0087] A typical implementation example of the accept method (using UserInfoAwareService as an example):
[0088] 4.3.3.3: Execute the matching service. Once the first (or all) service whose accept method returns true is found, the factory calls the doAware(obj) method of that service.
[0089] 4.3.4. Service Execution Assembly Logic
[0090] Implementation of the UserInfoAwareService.doAware(ViewPropertiesAware obj) method:
[0091] The value of this invention is ultimately realized in that it isolates the specific, potentially complex, data acquisition and encapsulation logic into an independent service class.
[0092] 4.3.5. Return of Control
[0093] After the assembly service is completed, control is returned sequentially: ViewPropertiesAwareService -> AwareServiceFactory -> Business Object -> Initial Business Service
[0094] ClueFllwupRcrdTblServiceImpl.
[0095] The business object `someBusinessObject` has been configured with the necessary public data, and the business service continues to use it to complete subsequent logic.
[0096] Key attributes and configurability:
[0097] The `testFlag` property: `AwareServiceFactory` can contain a boolean `testFlag` property. When set to `true`, the `execute` method can skip the actual data assembly logic or return mock data. This is very useful in unit testing and development phases, avoiding dependencies on real external services and improving testability.
[0098] Execution strategy: The factory supports different execution strategies, such as:
[0099] First-match strategy: Once the first service that returns true with accept is found, execute and return immediately.
[0100] The strategy of executing all services that return true with accept is suitable for situations where an object needs multiple types of shared data. The strategy pattern can be easily integrated into this architecture.
[0101] Beneficial effects:
[0102] 1. Revolutionary flexibility;
[0103] Transforming the timing of assembly from container control to business code control represents a qualitative leap. Developers can trigger assembly just like calling ordinary business methods, seamlessly integrating it into the business flow and demonstrating exceptional ability to handle complex and ever-changing business scenarios.
[0104] 2. Extreme scalability:
[0105] The factory pattern based on a dynamic registry makes adding a new assembly service exceptionally simple: just implement an interface and register it with the factory (either through automatic configuration or manual registration). No existing code needs to be modified, fully complying with the "open-closed principle".
[0106] 3. Excellent maintainability and clarity:
[0107] By separating the assembly logic for different public data into independent service classes, a perfect separation of concerns is achieved. The code structure is clear; the assembly logic for UserInfo resides within UserInfoAwareService, making it easy for developers to read, understand, and modify. Furthermore, the execution flow is transparent, facilitating debugging and troubleshooting.
[0108] 4. Strong testability:
[0109] Since the core interfaces and the factory are all POJOs, unit tests are very easy to write. The conditional logic of the UserInfoAwareService.accept() method can be tested separately, or the business service can be tested using MockAwareServiceFactory without starting the entire Spring container.
[0110] 5. Improved architectural robustness:
[0111] The "double dispatch" service selection mechanism enables the system to gracefully handle unknown or future data types. If an object is passed in that the factory cannot handle temporarily, it is sufficient to ensure that the accept method of no service returns true, thus preventing system errors and providing good fault tolerance.
[0112] 6. Technology independence:
[0113] The core of this architecture does not depend on Spring, which means that it can be ported to other Java frameworks or even other languages, giving it good technical viability.
[0114] The above specific embodiments further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.< / viewpropertiesawareservice>
Claims
1. A method for automatically assembling public data components, characterized in that, The implementation method includes: The public data component is a layered architecture, including: presentation layer, business logic layer, public data assembly layer, data access layer, and external services / data sources; Request entry point: The client request reaches the Controller in the presentation layer; Business logic processing: The Controller calls the Service method of the business logic layer; Triggering assembly: At the appropriate point in the Service method, the developer calls the doAware() method, passing in the public data object that needs to be assembled; Factory routing: The doAware() method internally delegates to the AwareServiceFactory.execute() method; Service execution; Data acquisition and assembly; Result returned: The assembled public data object is returned to the Service method to continue subsequent business logic, and finally the response is returned to the client.
2. The method for automatically assembling public data components according to claim 1, characterized in that, The data access layer includes: database calls, Feign client calls to remote services, or access to the cache.
3. The method for automatically assembling public data components according to claim 1, characterized in that, The service execution includes: The factory uses the "dual dispatch" mechanism to find the matching ViewPropertiesAwareService implementation and calls the doAware method.
4. The method for automatically assembling public data components according to claim 1, characterized in that, The data acquisition and assembly specifically includes: the matching service obtains the actual data through the data access layer and assembles it into the incoming public data object.
5. The method for automatically assembling public data components according to claim 1, characterized in that, The automatic assembly implementation method also includes: a complete interaction from the business code calling doAware() to the completion of data assembly.
6. The method for automatically assembling public data components according to claim 5, characterized in that, The complete interaction from the business code calling doAware() to the completion of data assembly specifically includes: Business calls include: Caller: ClueFllwupRcrdTblServiceImpl; Action: In its business method, call someBusinessObject.doAware(); someBusinessObject is a business object that implements the ViewPropertiesAware interface; The delegation is handled by the factory, implemented by the `someBusinessObject.doAware()` method: This method is very simple to implement, usually consisting of only one line of code: `awareServiceFactory.execute(this)`; The factory executes the routing; the internal logic of the `AwareServiceFactory.execute(ViewPropertiesAware obj)` method. Service execution assembly logic: Implementation of the UserInfoAwareService.doAware(ViewPropertiesAware obj) method: Control is returned after the assembly service is completed: ViewPropertiesAwareService->AwareServiceFactory->Business Object->Initial Business ServiceClueFllwupRcrdTblServiceImpl.
7. The method for automatically assembling public data components according to claim 6, characterized in that, The factory executes routing, and the internal logic of the AwareServiceFactory.execute method specifically includes: Iterate through the service list and obtain the ViewPropertiesAwareService list maintained internally by the factory; For each service in the list, the factory calls the accept(obj) method, passing the current business object obj as a parameter. Execute the matching service, find the first service whose accept method returns true, and the factory calls the service's doAware(obj) method.
8. The method for automatically assembling public data components according to claim 1, characterized in that, The implementation method also includes: key attributes and configurability; The `testFlag` property: `AwareServiceFactory` can contain a boolean `testFlag` property. When set to `true`, the `execute` method can skip the actual data assembly logic or return mock data. Execution strategy: The factory supports different execution strategies. First-match strategy: Once the first service that returns true with accept is found, execute and return immediately. Execute all services: Execute all services that return true with accept, suitable for situations where an object needs multiple types of common data.