Dependency Management and Tool Integration Method Based on Spring Boot
By customizing the starter package, Spring Boot's dependency management and tool integration methods are used to solve the problems of long importing project packages and high code complexity in Java back-end development, and simplifying package import, improving code readability and maintainability, and reducing learning costs.
Patent Information
- Application Number
- CN202211603752.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-14
- Publication Date
- 2025-08-01
- Estimated Expiration
- 2042-12-14
AI Technical Summary
In Java backend development, project packages are imported for a long time, high code complexity, difficult to understand code, and many repetitive methods, especially the waste of time and increased code complexity caused by unclear organization name and uncertain version of the project package.
By customizing the starter package, Spring Boot's dependency management and tool integration methods, including custom JavaBeans and configuration classes, implement package dependency management and tool integration, support hot-swap functions, reduce unnecessary package imports, and manage version control through dependencymanagement tags.
It simplifies the import process of project packages, reduces development time, improves code readability and maintainability, reduces learning costs, and improves universality and scalability among projects.
Smart Images

Figure 221214205512 
Figure 221214205515 
Figure DEST_PATH_IMAGE002
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer software, and provides a method for package dependency management and tool integration based on Spring Boot. Background Art
[0002] During the development of the Java backend, it is often encountered that the organization name of the project package is unknown, the full name of the project is unknown, and it is not known which version of the project package is more stable, resulting in an increase in the time spent on importing the framework package. Sometimes, useless work is done, and the imported package may not be usable. Moreover, this set of project packages may be used in other projects. Although copying and pasting is fast, if there are many projects, it is also a time-consuming task. In addition, during the process of writing business code, sometimes some data needs to be processed through a series of operations to obtain the correct result, and developers need to write this data processing process. However, in the process, classes such as time, date, and multithreading provided by the JDK are used, and these processing processes are very similar. Different results will be caused due to different input parameters. In response to this situation, some programmers may directly write the code and use it, but this will increase the complexity of the business layer code. While some senior programmers may integrate methods and design interfaces to make the methods highly available, but this will make the code difficult to understand for other developers, reducing the usability of the methods. Summary of the Invention
[0003] Aiming at the above two existing problems, the present invention realizes a method for package dependency management and tool integration based on Spring Boot through the custom starter mode of Spring Boot. The aim is to solve problems such as long framework package import time, complex code writing, difficult-to-understand code, and many duplicate methods in the above situation, thereby reducing the workload of programmers and spending more time on business logic. To achieve the above purpose, the technical solution of the present invention is as follows:
[0004] The present invention is a method for package dependency management and tool integration based on Spring Boot, mainly including two aspects. One is to customize the starter package, which describes the development process of package dependency management and tool integration. The other is to use the newly created starter package, which describes a usage step and the R & D effect. First, create a Spring Boot project and import the required dependency packages in the pom file, which can be appropriately modified and added according to needs. The specific description is in the first S3 step, and the package version arbitration is managed through the dependencymanagement tag. Tool integration mainly integrates a series of common methods that may be encountered in the project process, such as time, date, string, and methods that may be applicable to the project itself during project development, etc. Hereinafter, a specific description of tool integration will be made through the time method. The method integration of the time class is implemented by adding a JavaBean, and then the parameters are changed by modifying its attributes, and corresponding data processing methods are designed therein, such as conversion between time and string, obtaining year and month, adding and subtracting dates, and implementing thread safety, etc. After adding the configuration class, it can be used. After building the package, the customized package is deployed on the server for use. From the described method, considerations are made in terms of high availability, scalability, consistency, etc. of the package.
[0005] The first aspect of the invention, the steps for customizing the starter package are as follows:
[0006] S1: Create a spring boot project and name it dependentutil-starter
[0007] S2: Import the spring-boot-autoconfigure dependency, which must be imported for building the starter project.
[0008] S3: Add dependencies as needed. For example, for a front-end and back-end separated project, add dependencies such as Web, MySQL, Redis, Druid, Slf4j, MyBatis, etc. When adding dependencies, such as adding the web dependency, only the organization name and package name need to be added. To delete a dependency, only the corresponding dependcy needs to be deleted.
[0009]
[0010] S4: Design the JavaBean for the newly added method and make relevant configurations
[0011] S5: Implement the hot pluggable function
[0012] S6: Package the project
[0013] The second content of the invention is to use the starter package, which is the instruction for using the invention:
[0014] S1: Import the newly created dependentutil-starter project
[0015] S2: Configure the properties required for the JavaBean in properties or YAML
[0016] S3: Create the main program class, use @Enabledeput to determine whether to use the package
[0017] S4: Inject the class instance during business development, and operate the class instance to complete the call according to the requirements
[0018] The method for dependency management and tool integration based on Spring Boot includes the following steps:
[0019] S1: Create a new spring boot project, named dependencyutil-starter, and name it in the way of spring--boot-start-xxx;
[0020] S2: Import the spring-boot-autoconfigure dependency. When using custom methods later, call the annotations @ConfigurationProperties, @Configuration, @Conditional;
[0021] S3: Add dependencies as needed. First, use the dependencymanagement tag, then the dependencies tag inside it, and finally add the dependency dependency inside the dependencies tag. After adding the dependency, a properties tag needs to be added at the same level as dependencymanagement. The version control of each dependency is added in this tag, and the version control value is obtained through the ${} method in the dependency;
[0022] S4: Create a new JavaBean, customize its properties and methods. The properties here are used through the properties or YAML file when in use,
[0023] After writing the JavaBean, it is necessary to add @EnableConfigurationProperties to this class, pass in the class object of the current class, and then add the @configurationproperties annotation. The parameter of the annotation needs to pass in a prefix when in use;
[0024] After the configuration of the JavaBean is completed, a configuration class needs to be written to create an instance object of the JavaBean and inject the object into the container. An @Configuration annotation needs to be added to this configuration class so that it can be recognized by the container. Then, an @Bean annotation is added to the method, and an @Conditional annotation is added as needed.
[0025] S5: Add a new intermediate marker class. By judging the existence of this class, it is determined whether to inject the jar package into the container. Then, add a new annotation class to implement an annotation named @Enabledeput. Add @Target to the annotation class to describe the usage area of the annotation class. The role of @Retention is to define how long the annotation it annotates is retained. @Import introduces a class modified by @Configuration, and the instance marker class is introduced according to this. At the same time, judge this class on the configuration class of the JavaBean.
[0026] S6: Create a META-INF directory under the resources resource directory, and create a spring.factories file under it. Write in the spring.factories file
[0027] org.springframework.boot.autoconfigure.EnableAutoConfiguration=+, and configure as many as there are JavaBeans. All need to be configured. Otherwise, the new project will not find this class.
[0028] S7: Use maven to package the project, which includes two steps. First, use the clean command to clear the compiled files of the project, and then use the install command to package the project into a jar package. The project packaging step is completed and can be used by referencing it in the new project.
[0029] It also includes the use of the starter package:
[0030] S1: Create a new project for use, name it custom, and select the spring boot and JDK versions.
[0031] S2: Click on the pom file, and enter the organization name, project name, and version number defined in the previous content in the pom file. Import all the JavaBeans and dependencies defined in the first content into the new project, and no other changes need to be made. Add the same dependencies to the pom file.
[0032] S3: Add a properties configuration file, configure parameters in the file, with the prefix being the parameter of the JavaBean annotation @configurationproperties plus the property, assign values, and configure other information such as the port of the new project;
[0033] S4: Add a main program class, add the @Enabledeput annotation prepared for the hot-swapping technology on the main program class. Through this annotation, the jar package can be used as needed. With the annotation, the jar package will be used. Without the annotation, even if the dependency is introduced in the pom file, the new project container will not use this jar package;
[0034] S5: Add a business test class, instantiate the JavaBean class in the jar package through the @Autowired or @Resource annotation in the class, and then use the method of the JavaBean class defined in the previous content through the instantiated object.
[0035] The above steps are a simple description of two aspects of the research and use of the present invention. The detailed steps and explanations will be described in the embodiments. There are also similar methods for integrating time, date, etc. in our back-end development, but they are highly targeted, lack universality, and have a high learning cost. Therefore, a tool method integration package suitable for each team has been developed. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 is a flowchart of the content of the custom starter package provided by the present invention;
[0037] Figure 2 is a flowchart of the usage of the custom starter package provided by the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0038] The following will clearly and completely describe the technical solutions in the present invention in conjunction with the accompanying drawings. Obviously, the described content is part of the present invention, not all of it. Based on the content in the present invention, all other content obtained by those of ordinary skill in the art without creative efforts belongs to the scope protected by the present invention.
[0039] The method for dependency management and tool integration based on Spring Boot includes the following steps:
[0040] S1: Create a new spring boot project, name it dependencyutil-starter, and name it in the way of spring--boot-start-xxx;
[0041] S2: Import the spring-boot-autoconfigure dependency. When using custom methods later, call the annotations @ConfigurationProperties, @Configuration, and @Conditional;
[0042] S3: Add dependencies as needed. First, use the dependencymanagement tag, then the dependencies tag inside it, and finally add a dependency in the dependencies tag. After adding the dependency, add a properties tag at the same level as dependencymanagement. Add version control for each dependency in this tag, and the version control value is retrieved through the ${} method in the dependency;
[0043] S4: Create a JavaBean and customize its properties and methods. The properties here are used through properties or YAML files.
[0044] After writing the JavaBean, add @EnableConfigurationProperties to the class, pass in the class object of the current class, and then add the @configurationproperties annotation. The parameter of the annotation needs to pass in a prefix used during use;
[0045] After the configuration of the JavaBean is completed, write a configuration class, create an instance object of the JavaBean, and inject the object into the container. Add a @Configuration annotation to the configuration class so that it can be recognized by the container, and then add a @Bean annotation to the method. Add a @Conditional annotation as needed;
[0046] S5: Add a middle marker class. By judging the existence of this class, determine whether to inject the package into the container. Then add an annotation class, implement an annotation named @Enabledeput. Add @Target to the annotation class to indicate the usage area of the annotation class. The role of @Retention is to define how long the annotation it annotates is retained. @Import introduces a class modified by @Configuration, and introduce the instance marker class according to this. At the same time, judge this class on the JavaBean configuration class;
[0047] S6: Create a META-INF directory under the resources directory, and create a spring.factories file under it. Write in the spring.factories file
[0048] org.springframework.boot.autoconfigure.EnableAutoConfiguration=+, add as many as there are JavaBeans, and all need to be configured. Otherwise, the new project will not find this class;
[0049] S7: Package the project using maven, which includes two steps. First, use the clean command to clear the compiled files of the project, and then use the install command to package the project into a framework package. The project packaging step is completed and can be used by referencing it in the new project.
[0050] It also includes the use of the starter package:
[0051] S1: Create a new project, name it custom, and select the spring boot and JDK versions;
[0052] S2: Click on the pom file, and enter the organization name, project name, and version number defined in the previous content in the pom file. Import all the JavaBeans and dependencies defined in the first content into the new project, and no other changes need to be made. Add the same dependencies in the pom file;
[0053] S3: Add a properties configuration file, configure parameters in the file, with the prefix being the parameter of the JavaBean annotation @configurationproperties plus the property, and assign values to configure other information such as the port of the new project;
[0054] S4: Add a main program class, and add the @Enabledeput annotation prepared for the hot swapping technology on the main program class. Through this annotation, the jar package can be started as needed. Add the annotation to use the framework package. Without adding the annotation, even if the dependency is introduced in the pom file, the new project container will not use this framework package;
[0055] S5: Add a business test class, instantiate the JavaBean class in the package through the @Autowired or @Resource annotation in the class, and then use the methods of the JavaBean class defined in the previous content through the instantiated object.
[0056] Custom starter package
[0057] As Figure 1 shown, the following is the content flow chart of the custom starter package provided by the present invention. It mainly performs package dependency management through dependency management. When adding a package, modify the pom file. After modification, package and publish it for use. For unused packages, they can be dynamically deleted to reduce unnecessary package imports, thereby reducing the imported framework packages of the new project. In addition, there is also a problem here regarding version control. In a new project, the version of the package may not be input, or some vulnerable framework package versions may be used. Therefore, when designing, a fallback version control is required. After the package dependencies are completed, JavaBeans need to be written and configured so that the new project can use the configured methods. In addition, a hot-plug technology also needs to be implemented for the project so that this starter package can be used as needed in the new project. If needed, enable it on the startup class. If not needed, do not perform any processing. Although the package is imported, the container will not load the class.
[0058] Specifically, it includes the following steps:
[0059] S1: Create a new spring boot project named dependencyutil-starter. The official naming method for its own use is spring--boot-start-xxx. For custom packages, the official recommends using xxx-spring-boot-starter, but custom naming is also possible and can be made by one's own team. For example, the package in this case is named dependencyutil-starter. In addition, the organization name is defined as com.deput. The version of the package can use the default, such as 1.0-SNAPSHOT, or a version control in the form of 1.1.1.
[0060] S2: Import the spring-boot-autoconfigure dependency. This dependency must be imported as it is the dependency for automatic configuration. When customizing methods later, annotations inside it, such as @ConfigurationProperties, @Configuration, @Conditional, etc., are needed.
[0061] S3: Add dependencies as needed. First, use the dependencymanagement tag, then the dependencies tag inside it, and finally add a dependency inside the dependencies tag. After adding the dependency, a properties tag needs to be added at the same level as dependencymanagement. Add version control for each dependency in this tag. The version control values here are retrieved in the dependency through the ${} method. The advantage of the above steps is that when a new project needs to re-import packages, you can write the package version or not. And in multiple projects, only the current framework package needs to be introduced, and all the required packages can be imported. You can also make appropriate modifications and deletions according to the needs of your own project for personalized expansion, which saves a lot of time.
[0062] S4: Design a JavaBean for the newly added method and make relevant configurations. Taking the time format conversion as an example, the general idea is given below. During development, it is often encountered that this class is not thread-safe. When using it, it is not clear whether the class being used is thread-safe or not. Therefore, it is necessary to encapsulate the classes provided by the JDK itself for better use during development. First, create a new JavaBean and customize its properties and methods. The properties here are used through properties or YAML files during use. Therefore, when customizing, the properties need to be designed well to make the JavaBean highly extensible. The methods in the JavaBean can be written according to your own needs. For example, when converting time, two parameters, the time format and the time to be converted, need to be passed in, and the converted time is returned. How to modify in the specific process can use another parameter to pass values, thus implementing a method for time format conversion.
[0063] After writing the JavaBean, the @EnableConfigurationProperties needs to be added to this class, passing in the class object of the current class. The role of this annotation is to be able to discover this class during automatic assembly and thus be assembled into the container. Then, the @configurationproperties annotation also needs to be added, and the parameter of the annotation needs to pass in a prefix used during use, so as to achieve dynamic configuration of parameters.
[0064] After the configuration of JavaBean is completed, a configuration class needs to be written to create an instance object of the JavaBean and inject the object into the container so that it can be used by the newly created project. Just having @EnableConfigurationProperties is not enough; it only serves to discover. An @Configuration annotation needs to be added to this configuration class so that it can be recognized by the container. Then, an @Bean annotation is added to the method, and an @Conditional annotation can be added as needed to determine whether to add an instance of this class according to requirements. At the same time, an @ConditionalBean needs to be added to the class, and its function is to implement a hot-plug technology. The specific operation is in the next step.
[0065] S5: Implementation of hot-plug technology. The effect of this technology is that the entire package can be opened and used as needed, which is very convenient. Adding an annotation to the main class can inject the package into the container for use. Conversely, it will not be injected, and it cannot be used in the newly created project. Add a new intermediate marker class, and by judging the existence of this class, it is determined whether to inject the package into the container. Then add a new annotation class to implement an annotation named @Enabledeput. Add @Target to the annotation class to indicate the usage area of the annotation class. The role of @Retention is to define how long the annotation it annotates is retained. @Import can introduce a class modified by @Configuration (introduce the configuration class), and according to this, the instance marker class is introduced. At the same time, the JavaBean configuration class also judges this class, thus implementing the hot-plug technology to achieve on-demand opening and use.
[0066] S6: Create a META-INF directory under the resources directory and create a spring.factories file under it. Write in the spring.factories file
[0067] org.springframework.boot.autoconfigure.EnableAutoConfiguration=+(fully qualified name of the JavaBean class). Configure as many as there are JavaBeans, and all need to be configured. Otherwise, the newly created project will not discover this class.
[0068] S7: The last step is to package the project. Through this step, the project can be deployed to the server so that multiple projects can use it. The project is packaged using maven, which includes two steps. First, use the clean command to clear the compiled files of the project, and then use the install command to package the project into a package. The project packaging step is completed, and it can be used by referring to it in the newly created project.
[0069] As Figure 2 shown, the present invention provides a flowchart for using a custom starter package. After the above-mentioned custom starter steps are completed, the use of the starter package is carried out next. In this process, the convenience and speed of using the package can be fully experienced.
[0070] S1: Create a new project for use, the name can be defined by yourself, and select the spring boot and JDK versions
[0071] S2: Click on the pom file and enter the organization name, project name and version number defined in the previous content in the pom file. After this package is successfully introduced, it is equivalent to importing all the JavaBeans and dependencies defined in the first content into the new project, and no other changes need to be made. Of course, the same dependencies can be added to the pom file, the version can be written or not written, and new dependencies can be added to enable the project to have more functions.
[0072] S3: Add a new properties configuration file, configure parameters in the file, and the prefix is the parameter of the JavaBean annotation @configurationproperties plus the property, then it can be assigned values. In addition, other information such as the port of the new project needs to be configured to ensure the healthy operation of the project.
[0073] S4: Add a new main program class, and then add the @Enabledeput annotation prepared for the hot swap technology to the main program class. Through this annotation, the jar package can be opened and used as needed. With the annotation, the package will be used. Without the annotation, even if the dependency is introduced in the pom file, the new project container will not use this package.
[0074] S5: Add a new business test class, and in the class, instantiate the JavaBean class in the package through the @Autowired or @Resource annotation. Then, through the instantiated object, the methods of the JavaBean class defined in the previous content can be used, thus making the application simpler.
[0075] In summary, in the two steps of customizing the package and using the package in the present invention, the more difficult part is the design and implementation of customizing the package, which needs to be designed according to actual needs. The steps in the whole design are roughly described clearly, and the specific code implementation will not be shown. When using the custom package, the usage steps are roughly similar to those of creating a new project, but the specific usage methods are different. This allows programmers to have more time to understand the JavaBean methods and thus better use JavaBeans.
[0076] The various contents in this specification are described in a progressive manner, and each content has a detailed description of its respective design and use. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.
Claims
1. A method for dependency management and tool integration based on Spring Boot, characterized in that It includes the following steps: S1: Create a new spring boot project named dependencyutil-starter in the naming convention of spring--boot-start-xxx; S2: Import the spring-boot-autoconfigure dependency. When using custom methods later, call the annotations @ConfigurationProperties, @Configuration, and @Conditional; S3: Add dependencies as needed. First, use the dependencymanagement tag, then the dependencies tag inside it, and finally add the dependency in the dependencies tag. After adding the dependency, add a properties tag at the same level as dependencymanagement. Add version control for each dependency in this tag, and the version control value is retrieved in the dependency through the ${} method; S4: Create a JavaBean and customize its properties and methods. The properties here are used through properties or YAML files when in use; After writing the JavaBean, add @EnableConfigurationProperties to this class, pass in the class object of the current class, and then add the @configurationproperties annotation. The parameter of the annotation needs to pass in a prefix when in use; After the configuration of the JavaBean is completed, a configuration class needs to be written. Create an instance object of the JavaBean and inject the object into the container. Add a @Configuration annotation to this configuration class so that it can be recognized by the container, and then add a @Bean annotation to the method, and add a @Conditional annotation as needed; S5: Add a new intermediate marker class. By judging the existence of this class, it is determined whether to inject the package into the container. Then add a new annotation class and implement an annotation named @Enabledeput. Add @Target to the annotation class to indicate the usage area of the annotation class. The role of @Retention is to define how long the annotation annotated by it is retained. @Import introduces a class modified by @Configuration and introduces the instance marker class according to this. At the same time, judge this class in the configuration class of the JavaBean; S6: Create a META-INF directory under the resources resource directory and create a spring.factories file under it. Write in the spring.factories file org.springframework.boot.autoconfigure.EnableAutoConfiguration= +, configure as many as there are JavaBeans, and all need to be configured. Otherwise, the class will not be discovered in the newly created project; S7: Package the project using maven, which includes two steps. First, use the clean command to clear the compiled files of the project, and then use the install command to package the project into a framework package. The project packaging step is completed and can be used by referencing it in the newly created project.
2. The method for dependency management and tool integration based on Spring Boot according to claim 1, wherein It also includes the use of the starter package: S1: Create a new project, name it custom, and select the spring boot and JDK versions; S2: Click on the pom file and enter the organization name, project name, and version number defined in the previous content in the pom file. Import all the JavaBeans and dependencies defined in the first content into the new project, and there is no need to make any other changes. Add the same dependencies in the pom file; S3: Add a properties configuration file and configure the parameters in the file. The prefix is the parameter of the JavaBean annotation @configurationproperties plus the property, and assign values to configure other information such as the port of the new project; S4: Add a main program class and add the @Enabledeput annotation prepared for the hot swap technology on the main program class. Through this annotation, the jar package can be opened and used as needed. Add the annotation to use the framework package. Without the annotation, even if the dependency is introduced in the pom file, the new project container will not use this framework package; S5: Add a business test class, and instantiate the JavaBean class in the package through the @Autowired or @Resource annotation in the class. Then, use the methods of the JavaBean class defined in the previous content through the instantiated object.
Citation Information
Patent Citations
Method and device for realizing multi-version dependent isolation
CN110968340A
Method and tool for detecting java code dependency relationship and computer equipment
CN114327375A