WO2020215686A1 - spring框架泛型依赖注入方法、装置及计算机设备、存储介质 - Google Patents

spring框架泛型依赖注入方法、装置及计算机设备、存储介质 Download PDF

Info

Publication number
WO2020215686A1
WO2020215686A1 PCT/CN2019/117736 CN2019117736W WO2020215686A1 WO 2020215686 A1 WO2020215686 A1 WO 2020215686A1 CN 2019117736 W CN2019117736 W CN 2019117736W WO 2020215686 A1 WO2020215686 A1 WO 2020215686A1
Authority
WO
WIPO (PCT)
Prior art keywords
class file
class
bean
spring
spring container
Prior art date
Application number
PCT/CN2019/117736
Other languages
English (en)
French (fr)
Inventor
王建华
曹佩敬
Original Assignee
平安科技(深圳)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2020215686A1 publication Critical patent/WO2020215686A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/71Version control; Configuration management

Definitions

  • the embodiments of the present application belong to the field of artificial intelligence technology, and in particular relate to a spring framework generic dependency injection method, device, computer equipment, and storage medium.
  • the bean object is the instantiation of the java class.
  • the java class contains a series of methods and properties. These methods often rely on methods of other classes to run. Therefore, this dependency is used in the process of generating the bean object.
  • the existing dependency injection methods mainly include three types: constructor injection, setter injection, and interface injection.
  • Java class When a Java class uses generics, it can inherit the methods and properties of other classes, so that code can be reused, the amount of programming can be reduced, and the security risks caused by downward transformation can be solved. Its core composition is not set when declaring a class or interface The type of parameter or attribute. After using generics, the attributes in all classes are set dynamically. The inventor realized that when Java classes use generics to inherit the methods and properties of other classes, the framework of versions below spring 4.0 cannot implement dependency injection through the above three methods.
  • the embodiments of the present application provide a spring framework generic dependency injection method, device, computer equipment, and storage medium to solve the problem in the prior art that version frameworks below spring 4.0 do not support generic dependency injection. And to solve the problem that the injection method supported by the framework of versions below spring 4.0 may easily cause the constructor to be bloated and difficult to read, or the generated dependent object cannot enter the ready state immediately after the construction is completed, or is too invasive.
  • a spring framework generic dependency injection method including:
  • Traverse the class file collection generate a bean object according to each class file in the class file collection, and inject the generated bean object into the attribute of the target bean object to realize generic dependency injection.
  • a spring framework generic dependency injection device including:
  • the operation path acquisition module is used to monitor the startup process of the spring container, and after monitoring the end of the spring container startup, obtain the operation path of the target bean object that needs generic dependency injection;
  • the class file collection obtaining module is used to obtain class files from the corresponding target location according to the operation path, and determine whether each obtained class file corresponds to a dependent object, and when the judgment result has a class file corresponding to a dependent object , Collect the class files corresponding to a dependent object to form a class file collection;
  • Generic dependency injection module used to traverse the class file collection, generate bean objects according to each class file in the class file collection, and inject the generated bean objects into the attributes of the target bean object to realize generic dependencies injection.
  • a computer device including:
  • At least one processor and,
  • a memory communicatively connected with the at least one processor; wherein,
  • the memory stores computer readable instructions executable by the at least one processor, and the at least one processor implements the steps of the spring framework generic dependency injection method as described above when the computer readable instructions are executed by the at least one processor.
  • a non-volatile computer-readable storage medium having computer-readable instructions stored on the computer-readable storage medium, and when the computer-readable instructions are executed by at least one processor, the above-mentioned spring framework generic The steps of the dependency injection method.
  • Fig. 1 is a flowchart of a spring framework generic dependency injection method provided by an embodiment of the application
  • Figure 2 is a structural block diagram of a spring framework generic dependency injection device provided by an embodiment of the application
  • FIG. 3 is another structural block diagram of the spring framework generic dependency injection device provided by an embodiment of the application.
  • Fig. 4 is a structural block diagram of a computer device provided by an embodiment of the application.
  • the embodiment of the application provides a spring framework generic dependency injection method, which is specifically applied to a version of the spring framework that does not have the function of generic dependency injection, and can optimize the programming process, as shown in the flow chart shown in FIG.
  • Type dependency injection methods include:
  • the target bean object here is a dependent object, and the generation process of the dependent object depends on at least one dependent object; the operation path here refers to the operation path of the class to be injected into the target bean object.
  • S102 Obtain a class file from a corresponding target location according to the operation path, and determine whether each obtained class file corresponds to a dependent object, and when the result of the judgment is a class file corresponding to a dependent object, collect the class file corresponding to a dependent object.
  • the class files of the object form a collection of class files.
  • generating the target bean object through generic dependency injection is different from the traditional way of generating the target bean object through the spring container in the spring framework.
  • the way that the container generates the target bean object is carried out during the startup of the spring container, and generic dependency injection cannot be implemented during the startup of the spring container, so it is necessary to implement the generic of the target bean object separately after the spring container is started.
  • Dependency injection is carried out during the startup of the spring container, and generic dependency injection cannot be implemented during the startup of the spring container, so it is necessary to implement the generic of the target bean object separately after the spring container is started.
  • the spring container When the spring framework is running, the spring container will generate a series of bean objects and the dependencies between these bean objects during the startup process.
  • the properties or methods contained in these bean objects can generally be injected through interfaces, constructors, and setters. Injection and other methods are injected, but it does not include generic injection. Therefore, the required class file is obtained through the operation path of the target bean object that requires generic dependency injection configured outside the spring container, and the bean object is generated based on the class file, and Inject the generated bean object into the properties of the target bean object to achieve generic dependency injection of the target bean object.
  • the class file corresponding to a dependent object in step S102 means that the class file will be used directly or indirectly during the generation of a dependent object.
  • the generation of a dependent object A depends on the dependent object.
  • Object B and dependent object C and the generation of dependent object B and dependent object C does not need to rely on other objects.
  • the corresponding class files of dependent object B and dependent object C are directly used to generate dependent object A
  • the generation of dependent object B and/or dependent object C also needs to rely on other objects, that is, dependent object B and/or dependent object C itself is also a dependent object
  • dependent object B needs to depend on the dependent object
  • the class file corresponding to dependent object D is indirectly used to generate dependent object A.
  • the class file is specifically a binary file that defines a class or interface, and the corresponding class or interface can be obtained based on the class file.
  • the definition information of the class or interface can be directly included in the class file , It can also be generated by a class loader. Unless otherwise specified, the definition information of the class or interface mentioned in this embodiment is directly included in the class file. Since the dependent object is a class, the dependent object is dependent on The object must also be a class.
  • the step of judging whether each acquired class file corresponds to a dependent object includes: determining the class file corresponding to the class according to the class identification information, and then downloading from the corresponding class file according to the dependent identification information Filter the class file corresponding to a dependent object in the class file.
  • the class identification information can be information contained in the class file, or information configured outside the class file.
  • the feature code information of the class or interface can be included in the file structure of the class file. The identification feature code information achieves the purpose of identifying the class or interface.
  • the class identification information corresponding to each class file under the target path can be configured through an independent configuration file; and the dependent identification information can be included in the class
  • the information in the file can also be information configured outside the class file. For the latter, it can be configured through a separate configuration file, or configured in the properties of the target bean object.
  • the class file can generate bean objects through reflection and dynamic proxy.
  • the reflection and dynamic proxy belong to the internal mechanism of the java program.
  • any class can know all its properties and methods, and any bean object can call any of its methods and properties.
  • This dynamic acquisition of information and dynamic method call function is called the reflection mechanism of java;
  • the agent is the process of executing related methods based on the class name, method name, and parameters provided by the user, and returning the result.
  • the purpose of reflection and dynamic proxy is to instantiate the class defined in the class file to obtain the bean object.
  • the target location corresponding to the operation path of the target bean object that needs to perform generic dependency injection may be a local storage or a cloud storage.
  • the spring framework generic dependency injection method may further include: when the judgment result does not exist a class file corresponding to a dependent object, prompting an operation error, and requesting a new one again Operation path, obtain new class files according to the new operation path, and judge whether each newly obtained class file corresponds to a dependent object; in this way, it can avoid the failure of injection caused by the input error of the operation path.
  • the step of monitoring the startup process of the spring container may specifically be to start monitoring the startup process of the spring container while the spring container is started, until the start of the spring container ends. Stop monitoring.
  • the step of monitoring the startup process of the spring container may specifically be to start timing when the spring container is started, and when the timing reaches a preset duration, start the startup process of the spring container The monitoring is stopped until the start of the spring container ends, so that you don’t have to keep monitoring and waste system resources when the spring container starts for a long time.
  • the premise of this monitoring method is that the spring can be estimated.
  • the startup duration of the container or the startup duration of the spring container has been counted in advance, and the timing duration must be lower than the startup duration of the spring container.
  • the timing time can be adjusted in real time according to the estimated start-up duration of the spring container, and it is sufficient to ensure that the timing duration is lower than the start-up duration of the spring container.
  • the method further includes: generating a dependency relationship between each bean object, and combining each bean object The dependencies between the two are injected into the properties of the target bean object.
  • the method before the spring container is started, includes a step of configuring the operation path of the target bean object.
  • the configuration of the operation path of the target bean object can be realized by obtaining the operation path input by the input terminal in real time. This method can configure the new operation path in real time; in addition, the configuration requires generic dependency injection
  • the operation path of the target bean object can also be realized by reading a pre-stored configuration file and reading the operation path information from the configuration file.
  • multiple operation paths may be configured. When there are more than two operation paths configured, obtaining the operation path of the target bean object may specifically include obtaining all of the configuration.
  • the operation path is used to read class files from multiple target locations. There is a situation where there are different versions of a class file in each class file read (the class file can contain information identifying the version), then you can Obtain the latest version of the class file, and remove the class files of other versions from all the obtained class files.
  • the step of obtaining the operation path of the target bean object that requires generic dependency injection may specifically include filtering and obtaining one of the two or more operation paths according to the configuration information in the obtaining instruction, or Several operating paths. For example, there are three operation paths, and the target positions corresponding to the three operation paths have different modification times, and the operation path corresponding to the most recently modified target position can be obtained.
  • control layer For most web projects implemented by java, it usually includes the code implementation of the four levels of control layer (controller), business layer (service), data operation layer (dao) and data table entity (model). There is a calling relationship or an operation relationship between, for example, the control layer calls the business layer, the business layer then calls the data operation layer, and the operation layer directly operates the database. These three levels will use data table entities to varying degrees, so web projects implemented through java
  • the general code structure is: the business layer is the attribute of the control layer, the data operation layer is the attribute of the business layer, and the data table entity is the input parameter in the method of the control layer, business layer, and data operation layer. Return type.
  • the data operation layer and business layer will have operations to add, delete, modify and check data tables, but the input parameters and return value types correspond to different data table entities, although the methods in the data operation layer and business layer classes are different , But the actual operation logic is the same, only for different data sheet operations, so there is the possibility of repeated code writing.
  • the problem of repeated writing code can be solved through generics, that is, the business layer By inheriting the operation method of adding, deleting, modifying, and checking data tables of the data operation layer by generics, the operation method of adding, deleting, modifying, and checking data tables by the data operation layer can be injected into the business layer by means of generic dependency injection.
  • the data operation layer declares four classes, including add operation method, delete operation method, modify operation method, and find operation method. These four classes need to be inherited by the business layer, then first configure the operation path, here is Refers to the operation path of the four method classes to be injected in the configuration data operation layer. After the configuration is completed, it will continue to monitor the startup process of the spring container. When the spring container is monitored, the operation path of the four method classes will be obtained. Obtain the class file from the location, find the class files corresponding to the four method classes to form a class file collection, and based on the class file collection, generate the corresponding bean for each class file in the class file collection through reflection and dynamic proxy.
  • Object that is, dependent object
  • Dependency is injected into the properties of the target bean object in the business layer to complete generic dependency injection, and then by calling these target bean objects, the business layer also implements the operation method of adding, deleting, modifying and checking, that is, realizing generic dependency injection.
  • the spring framework generic dependency injection method provided by the embodiments of this application, it can be applied to the version of the spring framework that does not have the function of generic dependency injection.
  • the generic dependency can be realized by obtaining the class file from the set path after the spring container starts. Injection, this method can simplify the dependencies between objects, make the program more simplified, easier to read, and less intrusive.
  • the generated dependent objects can enter the ready state immediately after the construction is completed, which can effectively improve the efficiency of the program.
  • the embodiment of the application also provides a spring framework generic dependency injection device to implement generic dependency injection in a version of the spring framework that does not have the generic dependency injection function.
  • the spring framework generic dependency injection The device includes an operation path acquisition module 10, a class file collection acquisition module 20, and a generic dependency injection module 30, where:
  • the operation path obtaining module 10 is used to monitor the startup process of the spring container, and after monitoring the end of the spring container startup, obtain the operation path of the target bean object that needs generic dependency injection; the target bean object here is a dependent object , The generation process of dependent objects must depend on at least one dependent object; the operation path here refers to the operation path of the class to be injected into the target bean object.
  • the target location corresponding to the operation path of the target bean object that needs to perform generic dependency injection may be a local storage or a cloud storage.
  • the class file collection acquisition module 20 is configured to acquire class files from the corresponding target location according to the operation path, and determine whether each acquired class file corresponds to a dependent object.
  • the result of the judgment is a class corresponding to a dependent object
  • class files corresponding to a dependent object are collected to form a class file collection; for the description of the class file corresponding to a dependent object, please refer to the description of the relevant technical content in the above method embodiment, which will not be repeated here.
  • the class file collection acquisition module 20 determines whether each acquired class file corresponds to a dependent object, it is specifically used to determine the class file corresponding to the class according to the class identification information, and according to the dependent identification information
  • the class file corresponding to a dependent object is filtered from the class file corresponding to the class; for the description of the class identification information and the dependent identification information, please refer to the description of the related technical content in the above method embodiment. Repeat it again.
  • the class file collection acquiring module 20 is specifically configured to prompt an operation error when the judgment result does not have a class file corresponding to a dependent object, and request a new operation path again, according to The new operation path obtains new class files, and judges whether each newly obtained class file corresponds to a dependent object; in this way, it is possible to avoid the failure of injection caused by the input error of the operation path.
  • the generic dependency injection module 30 is used to traverse the set of class files, generate bean objects according to each class file in the set of class files, and inject the generated bean objects into the attributes of the target bean object to achieve generic Type dependency injection; in this embodiment, the class file can generate bean objects through reflection and dynamic proxy.
  • the reflection and dynamic proxy please refer to the description of the relevant technical content in the above method embodiment. This will not be repeated here.
  • the operation path acquisition module 10 when the operation path acquisition module 10 monitors the startup process of the spring container, it is specifically used to enable monitoring of the startup process of the spring container at the same time that the spring container starts, until the spring container Stop monitoring at the end of the start.
  • the spring framework generic dependency injection device may further include a timing module 40, and the operation path acquisition module 10 is specifically used to monitor the startup process of the spring container when the spring When the container is started, the timing module 40 is called to start timing.
  • the operation path acquisition module 10 starts monitoring the startup process of the spring container until the spring Stop listening when the container starts, so that you don’t have to monitor all the time and waste system resources when the spring container has a long startup time.
  • the premise of this monitoring method is to be able to estimate the startup time of the spring container or make statistics in advance
  • the timing duration of the timing module 40 must be lower than the start-up duration of the spring container.
  • the timing time counted by the timing module 40 can be adjusted in real time according to the estimated start-up duration of the spring container to ensure that the timing duration of the timing module 40 is lower than that of the spring container.
  • the generic dependency injection module 30 after the generic dependency injection module 30 generates a bean object according to each class file in the class file set, the generic dependency injection module 30 is also used to generate each bean The dependency between the objects, the dependency between each bean object is injected into the attributes of the target bean object.
  • the spring framework generic dependency injection device may further include a configuration module 50 for configuring the target bean object. Operation path.
  • the configuration module 50 may include an input portal, and configuration is realized by obtaining the operation path of the input portal input in real time; in other embodiments, the configuration module 50 may also be realized by operating a configuration file Configuration. In an implementable solution, the configuration module 50 can configure multiple operation paths during the configuration process of the operation path.
  • the operation path acquisition module 10 When obtaining the operation path of the target bean object, it can be specifically used to obtain all the configured operation paths to read class files from multiple target locations; in other feasible solutions, when the configuration module 50 is configured with two When there are more than one operation paths, the operation path obtaining module 10 may be specifically used to obtain one or more operation paths from the two or more operation paths according to the configuration information in the obtaining instruction when obtaining the operation path of the target bean object.
  • the spring framework generic dependency injection device provided by the embodiments of this application can be applied to a version of the spring framework that does not have the function of generic dependency injection by itself.
  • Generic dependencies are realized by obtaining class files from the set path after the spring container is started. Injection, this method can simplify the dependencies between objects, make the program more simplified, easier to read, and less intrusive.
  • the generated dependent objects can enter the ready state immediately after the construction is completed, which can effectively improve the efficiency of the program.
  • An embodiment of the present application also provides a computer device.
  • the computer device includes at least one processor 401, and a memory 402 communicatively connected to the at least one processor 401.
  • the memory 402 stores computer-readable instructions that can be executed by the at least one processor 401, and the computer-readable instructions are executed by the at least one processor 401 to enable the at least one processor 401 It can perform the steps of the spring framework generic dependency injection method as described above.
  • the memory 402 in the embodiment of the present application is a non-volatile computer-readable storage medium, which can be used to store non-volatile software programs, non-volatile computer-executable programs and modules, as in the above-mentioned embodiments of the present application
  • the memory 402 may include a program storage area and a data storage area, where the program storage area may store an operating system and an application program required by at least one function; the data storage area may store spring framework generic dependency injection Data created during the processing of the method, etc.
  • the memory 402 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other non-volatile solid-state storage devices;
  • the memory 402 may optionally include remote memories that are set remotely relative to the processor 401. These remote memories may be connected to a computer device that performs domain name filtering through a network. Examples of the foregoing network include, but are not limited to, the Internet and internal enterprise Network, local area network, mobile communication network and their combination.
  • the computer device that executes the spring framework generic dependency injection method may also include an input device 403 and an output device 4040; wherein the input device 403 may obtain user operation information on the computer device, and the output device 4040 may include Display devices such as displays.
  • the processor 401, the memory 402, the input device 403, and the output device 4040 may be connected through a bus or other methods. In FIG. 4, the connection through a bus is taken as an example.
  • the steps of the spring framework generic dependency injection method in the above embodiment can be executed, and it has the technical effects of the above method embodiment.
  • the steps of the spring framework generic dependency injection method in the above embodiment can be executed, and it has the technical effects of the above method embodiment.
  • the embodiment of the present application also provides a non-volatile computer-readable storage medium, the computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by at least one processor,
  • the steps of the spring framework generic dependency injection method described above have the technical effects of the above method embodiment when the steps of the method are executed.
  • the technical content provided in the example please refer to the method implementation of this application The technical content provided in the example.
  • the embodiment of the application also provides a computer program product, which can execute the spring framework generic dependency injection method provided in the method embodiment of the application, and has the corresponding functional modules and beneficial effects of the execution method.
  • a computer program product which can execute the spring framework generic dependency injection method provided in the method embodiment of the application, and has the corresponding functional modules and beneficial effects of the execution method.
  • the above-mentioned integrated unit implemented in the form of a software functional unit may be stored in a computer readable storage medium.
  • the above-mentioned software functional unit is stored in a storage medium and includes several instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) or an intelligent terminal device or a processor (Processor) execute the various embodiments of the present application Part of the steps of the method.
  • the aforementioned storage media include: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disks or optical disks, etc., which can store computer readable instructions. Medium.
  • the disclosed apparatus and method may be implemented in other ways.
  • the device embodiments described above are merely illustrative, for example, the division of the modules is only a logical function division, and there may be other divisions in actual implementation, for example, two or more modules or components Can be combined or integrated into another system, or some features can be ignored or not implemented.
  • modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed to two or more network units on. Some or all of the modules may be selected according to actual needs to achieve the objectives of the solutions of the embodiments.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Security & Cryptography (AREA)
  • Computing Systems (AREA)
  • Stored Programmes (AREA)

Abstract

本申请属于人工智能技术领域,涉及一种spring框架泛型依赖注入方法、装置及计算机设备、存储介质,所述方法包括:在监测到spring容器启动结束后,获取需要进行泛型依赖注入的目标bean对象的操作路径;根据操作路径获取class文件,收集对应于一个依赖对象的class文件形成class文件集合;根据所述class文件集合中的每个class文件生成bean对象并注入所述目标bean对象的属性中,实现泛型依赖注入。本申请提供的方案可应用于自身不具有泛型依赖注入功能的spring框架,通过在spring容器启动之后从设定的路径获取class文件来实现泛型依赖注入,这种方式能够简化对象之间的依赖关系,程序更加简化,容易阅读,侵入性弱,生成的依赖对象在构造完成后可马上进入就绪状态,能提高程序运行效率。

Description

spring框架泛型依赖注入方法、装置及计算机设备、存储介质
交叉引用
本申请以2019年04月23日提交的申请号为201910327704.2,名称为“spring框架泛型依赖注入方法、装置及计算机设备、存储介质”的中国申请专利申请为基础,并要求其优先权。
技术领域
本申请实施例属于人工智能技术领域,尤其涉及一种spring框架泛型依赖注入方法、装置及计算机设备、存储介质。
背景技术
对于基于spring框架的应用程序,程序功能的实现过程中,需生成一系列的bean对象,通过操作这些bean对象来实现具体的功能。
bean对象是java类的实例化,java类包含一系列的方法和属性,这些方法往往会依赖其他类的方法来运行,因此在生成bean对象的过程中会利用到这种依赖关系,通过依赖关系来引用依赖对象的方法和属性,并将其注入到bean对象中,现有依赖注入方式主要包括构造方法注入(constructor injection),setter方法注入(setter injection)以及接口注入(interface injection)三类。
Java类使用泛型时可以继承其他类的方法和属性,从而可以复用代码,减少编程量,解决向下转型所带来的安全隐患,其核心的组成就是在声明类或接口的时候不设置参数或属性的类型,使用泛型之后,所有类中属性都是动态设置的。发明人意识到,当java类使用泛型继承其他类的方法和属性时,在spring4.0以下的版本框架无法通过上述三种方式来实现依赖注入。
此外,对于复杂的依赖关系,比如依赖对象比较多的时候,如果采用构造方法注入,会因参数列表较长而导致构造器过于臃肿,使得难以阅读,Spring在创建Bean实例时,需要同时实例化其依赖的全部实例,因而导致性能下降;采用setter方法注入尽管可以解决性能下降的问题,然而生成的依赖对象无法在构造完成后马上进入就绪状态;接口注入比较死板和烦琐,如果需要注入依赖对象,被注入对象就必须声明和实现另外的接口,且其强制被注入对象实现 不必要的接口,侵入性太强。
发明内容
有鉴于此,本申请实施例提供一种spring框架泛型依赖注入方法、装置及计算机设备、存储介质,以解决现有技术中spring4.0以下的版本框架不支持泛型依赖注入方式的问题,以及解决spring4.0以下的版本框架支持的注入方式或容易导致构造器臃肿难以阅读,或生成的依赖对象在构造完成后无法马上进入就绪状态,或侵入性太强的问题。
一种spring框架泛型依赖注入方法,包括:
监听spring容器的启动过程,在监测到spring容器启动结束后,获取需要进行泛型依赖注入的目标bean对象的操作路径;
根据所述操作路径从对应的目标位置获取class文件,并判断每个获取的class文件是否对应于一个依赖对象,当判断结果存在对应于一个依赖对象的class文件时,收集对应于一个依赖对象的class文件形成class文件集合;
遍历所述class文件集合,根据所述class文件集合中的每个class文件生成bean对象,将生成的bean对象注入所述目标bean对象的属性中,实现泛型依赖注入。
一种spring框架泛型依赖注入装置,包括:
操作路径获取模块,用于监听spring容器的启动过程,在监测到spring容器启动结束后,获取需要进行泛型依赖注入的目标bean对象的操作路径;
class文件集合获取模块,用于根据所述操作路径从对应的目标位置获取class文件,并判断每个获取的class文件是否对应于一个依赖对象,当判断结果存在对应于一个依赖对象的class文件时,收集对应于一个依赖对象的class文件形成class文件集合;
泛型依赖注入模块,用于遍历所述class文件集合,根据所述class文件集合中的每个class文件生成bean对象,将生成的bean对象注入所述目标bean对象的属性中,实现泛型依赖注入。
一种计算机设备,包括:
至少一个处理器;以及,
与所述至少一个处理器通信连接的存储器;其中,
所述存储器存储有可被所述至少一个处理器执行的计算机可读指令,所述至少一个处理器执行所述计算机可读指令时实现如上所述的spring框架泛型依 赖注入方法的步骤。
一种非易失性的计算机可读存储介质,所述计算机可读存储介质上存储有计算机可读指令,所述计算机可读指令被至少一个处理器执行时实现如上所述的spring框架泛型依赖注入方法的步骤。
本申请的一个或多个实施例的细节在下面的附图和描述中提出,本申请的其他特征和优点将从说明书、附图以及权利要求变得明显。
附图说明
为了更清楚地说明本申请的方案,下面将对实施例描述中所需要使用的附图作一个简单介绍,显而易见地,下面描述中的附图是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1为本申请实施例提供的spring框架泛型依赖注入方法的流程图;
图2为本申请实施例提供的spring框架泛型依赖注入装置的结构框图;
图3为本申请实施例提供的spring框架泛型依赖注入装置的另一结构框图;
图4为本申请实施例提供的计算机设备的结构框图。
具体实施方式
为了使本技术领域的人员更好地理解本申请方案,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述。除非另有定义,本文所使用的所有的技术和科学术语与属于本申请的技术领域的技术人员通常理解的含义相同。
在说明书中的各个位置出现的“实施例”该短语并不一定均是指相同的实施例,也不是与其它实施例互斥的独立的或备选的实施例。本领域技术人员显式地和隐式地理解的是,本文所描述的实施例可以与其它实施例相结合。
本申请实施例提供一种spring框架泛型依赖注入方法,具体应用于自身不具备泛型依赖注入功能的spring框架版本,能够优化编程过程,如图1所示的流程框图,所述spring框架泛型依赖注入方法包括:
S101、监听spring容器的启动过程,在监测到spring容器启动结束后,获取需要进行泛型依赖注入的目标bean对象的操作路径。此处的目标bean对 象是一个依赖对象,依赖对象的生成过程需依赖于至少一个被依赖对象;此处的操作路径是指待注入目标bean对象的类的操作路径。
S102、根据所述操作路径从对应的目标位置获取class文件,并判断每个获取的class文件是否对应于一个依赖对象,当判断结果存在对应于一个依赖对象的class文件时,收集对应于一个依赖对象的class文件形成class文件集合。
S103、遍历所述class文件集合,根据所述class文件集合中的每个class文件生成bean对象,将生成的bean对象注入所述目标bean对象的属性中,实现泛型依赖注入。
在本申请实施例中,对于不具有泛型依赖注入功能的spring框架版本,通过泛型依赖注入生成目标bean对象与spring框架中传统的通过spring容器生成目标bean对象的方式不同,传统的通过spring容器生成目标bean对象的方式是在spring容器启动的过程中进行的,而泛型依赖注入则无法在spring容器启动过程中实现,故需要在spring容器启动结束之后单独来实现目标bean对象的泛型依赖注入。
在spring框架运行时,spring容器在启动过程中会生成一系列的bean对象,以及生成这些bean对象之间的依赖关系,这些bean对象包含的属性或方法一般可通过接口注入、构造器注入、setter注入等方式注入,但是却不包含泛型注入,因此通过在spring容器之外配置的需要泛型依赖注入的目标bean对象的操作路径来获取需要的class文件,基于class文件来生成bean对象,并将生成的bean对象注入目标bean对象的属性中,以此来实现目标bean对象的泛型依赖注入。
在本申请实施例中,步骤S102所述的class文件对应一个依赖对象是指该class文件在一个依赖对象的生成过程中会被直接或者间接用到,比如一个依赖对象A的生成依赖于被依赖对象B和被依赖对象C,而被依赖对象B和被依赖对象C的生成不需要依赖其他对象,此时被依赖对象B和被依赖对象C各自对应的class文件直接用于依赖对象A的生成,假如被依赖对象B和/或被依赖对象C的生成也需要依赖其他对象,也即被依赖对象B和/或被依赖对象C本身也是一个依赖对象,若被依赖对象B需依赖于被依赖对象D,则被依赖对象D对应的class文件则是间接用于依赖对象A的生成。在本实施例中,class文件具体是定义了一个类或者接口的二进制文件,基于class文件能够得到相应的类或接口,需要说明的是,类或者接口的定义信息可以是直接包含在class文件中, 也可以是通过类加载器生成,除非特殊说明,本实施例中提到的类或者接口的定义信息直接包含在class文件中,由于依赖对象是一个类,则与依赖对象相对应的被依赖对象也必须是一个类。
在本申请一些实施例中,所述判断每个获取的class文件是否对应于一个依赖对象的步骤包括:根据类标识信息确定对应于类的class文件,在根据依赖标识信息从所述对应于类的class文件中筛选对应于一个依赖对象的class文件。具体的,所述类标识信息可以是包含在class文件中的信息,也可以是在class文件以外配置的信息,对于前者,可以在class文件的文件结构中包含类或者接口的特征码信息,通过识别特征码信息达到识别类或者接口的目的,对于后者,可通过独立的配置文件来配置目标路径下各class文件所对应的类标识信息;而对于所述依赖标识信息,可以是包含在class文件中的信息,也可以是在class文件以外配置的信息,其中对于后者,可通过独立的配置文件来配置,或者是在目标bean对象的属性中配置。
在步骤S103中,在本申请一些实施例中,所述class文件可通过反射和动态代理的方式生成bean对象,所述的反射和动态代理属于java程序的内部机制,其中,在java程序的运行时刻,对于任何一个类都能够知道它的所有属性和方法,对任意一个bean对象都能够调用它的任意方法和属性,这种动态获取信息以及动态调用方法的功能称为java的反射机制;动态代理则是根据用户提供类名、方法名、参数来执行相关方法,并返回结果的过程。在这里,反射和动态代理的目的是对class文件定义的类进行实例化以获得bean对象。
本申请实施例中,需要进行泛型依赖注入的目标bean对象的操作路径对应的目标位置可以是本地存储器也可以是云存储器。
在本申请一些实施例中,在步骤S102中,所述spring框架泛型依赖注入方法还可包括:当所述判断结果不存在对应于一个依赖对象的class文件,提示操作错误,重新请求新的操作路径,根据新的操作路径获取新的class文件,并判断每个新获取的class文件是否对应于一个依赖对象;通过这种方式可以避免操作路径输入错误导致注入失败的情况。
在本申请一些实施例中,所述监听spring容器的启动过程的步骤具体可以是在所述spring容器启动的同时开启对所述spring容器的启动过程的监听,直到所述spring容器的启动结束时停止监听。在另一些实施例中,所述监听spring容器的启动过程的步骤具体也可以是在所述spring容器启动的同时开始计时,当计时达到预设的时长时,开启对所述spring容器的启动过程的监听, 直到所述spring容器的启动结束时停止监听,这样可以在spring容器的启动时间较长的情况下不必一直监听而浪费系统资源,当然这种监听方式的前提是能够预估所述spring容器的启动时长或者预先统计过所述spring容器的启动时长,计时时长必须低于所述spring容器的启动时长。当然,在实际方案中,所述的计时时间可根据预估的所述spring容器的启动时长的变化而对应实时调整,保证计时时长低于所述spring容器的启动时长即可。
作为本申请可实施的方式,在所述根据所述class文件集合中的每个class文件生成bean对象的步骤之后还包括:生成各所述bean对象之间的依赖关系,将各所述bean对象之间的依赖关系一并注入所述目标bean对象的属性中。
在本申请一些实施例中,在所述spring容器启动之前,所述方法包括配置所述目标bean对象的操作路径的步骤。在本实施例中,配置所述目标bean对象的操作路径可通过实时获取输入端输入的操作路径的方式来实现,这种方式可以实时配置新的操作路径;此外,配置需要进行泛型依赖注入的目标bean对象的操作路径也可以是通过读取预存的配置文件,从配置文件中读取操作路径信息的方式来实现。在本申请一些实施例中,在进行操作路径的配置过程中,可配置多条操作路径,当配置有两条以上操作路径时,获取所述目标bean对象的操作路径具体可包括获取配置的全部操作路径,以从多个目标位置中读取class文件,存在这样的情况,读取的各class文件中,存在一个class文件的不同版本(在class文件中可包含标识版本的信息),则可获取最新版本的class文件,而将其他版本的class文件从获取到的全部class文件中剔除。
在另一些实施例中,所述获取需要进行泛型依赖注入的目标bean对象的操作路径的步骤具体可包括根据获取指令中的配置信息从所述两条以上操作路径中筛选获取其中的一条或者几条操作路径。比如有三条操作路径,三条操作路径对应的目标位置中的修改时间不同,可获取最近修改的目标位置对应的操作路径。
下面以一个实例对上述所述spring框架泛型依赖注入方法中的步骤进行解释说明。
对于大多数的通过java实现的web项目,通常都包括控制层(controller)、业务层(service)、数据操作层(dao)和数据表实体(model)这四个层面的代码实现,各层面之间存在调用关系或者操作关系,比如控制层调用业务层,业务层再调用数据操作层,操作层直接操作数据库,这三个层面都会不同程度的使用到数据表实体,因此通过java实现的web项目一般的代码结构为:业务 层是控制层的属性,数据操作层是业务层的属性,而数据表实体是控制层、业务层、数据操作层这三个层面的类的方法中的入参或者返回类型。其中,在数据操作层、业务层都会具备有对数据表进行增删改查的操作,只是入参和返回值类型对应了不同的数据表实体,虽然数据操作层、业务层的类中的方法不同,但是实际的操作逻辑是一致的,只是针对的是不同的数据单操作,因此存在重复的代码编写的可能,对于大型的web项目开发,通过泛型可以解决重复编写代码的问题,即业务层通过泛型继承数据操作层的对数据表的增删改查的操作方法,具体可以通过泛型依赖注入的方式将数据操作层对数据表的增删改查的操作方法注入到业务层。
假如现在包括数据操作层声明了四个类,分别包含有增加操作方法、删除操作方法、修改操作方法和查找操作方法,这四个类需要被业务层继承,那么首先配置操作路径,此处是指配置数据操作层中待注入的四个方法类的操作路径,配置完成后持续监听spring容器的启动过程,当监测到spring容器启动结束时获取四个方法类的操作路径,根据操作路径从目标位置获取class文件,从中找到这四个方法类对应的class文件形成class文件集合,基于该class文件集合,对所述class文件集合中的每个class文件通过反射和动态代理的方式生成对应的bean对象(也即依赖对象),如果这四个bean对象之间存在依赖关系,还会生成这四个bean对象之间的依赖关系,而后将生成这四个bean对象及四个bean对象之间的依赖关系注入业务层中的目标bean对象的属性中,完成泛型依赖注入,之后通过调用这些目标bean对象,业务层也实现了增删改查的操作方法,即实现了泛型依赖注入。
根据本申请实施例提供的spring框架泛型依赖注入方法,可以应用于自身不具有泛型依赖注入功能的spring框架版本,通过在spring容器启动之后从设定的路径获取class文件来实现泛型依赖注入,这种方式能够简化对象之间的依赖关系,使得程序更加简化,容易阅读,同时侵入性弱,生成的依赖对象在构造完成后可马上进入就绪状态,能有效提高程序运行效率。
本申请实施例还提供一种spring框架泛型依赖注入装置,以在不具有泛型依赖注入功能的spring框架版本中实现泛型依赖注入,如图2所示,所述spring框架泛型依赖注入装置包括操作路径获取模块10、class文件集合获取模块20和泛型依赖注入模块30,其中:
所述操作路径获取模块10用于监听spring容器的启动过程,在监测到spring容器启动结束后,获取需要进行泛型依赖注入的目标bean对象的操作路 径;此处的目标bean对象是一个依赖对象,依赖对象的生成过程需依赖于至少一个被依赖对象;此处的操作路径是指待注入目标bean对象的类的操作路径。本申请实施例中,需要进行泛型依赖注入的目标bean对象的操作路径对应的目标位置可以是本地存储器也可以是云存储器。
所述class文件集合获取模块20用于根据所述操作路径从对应的目标位置获取class文件,并判断每个获取的class文件是否对应于一个依赖对象,当判断结果存在对应于一个依赖对象的class文件时,收集对应于一个依赖对象的class文件形成class文件集合;其中关于所述的class文件对应一个依赖对象的说明可参阅上述方法实施例中的相关技术内容描述,在此不再赘述。
在本申请一些实施例中,所述class文件集合获取模块20判断每个获取的class文件是否对应于一个依赖对象时具体用于根据类标识信息确定对应于类的class文件,在根据依赖标识信息从所述对应于类的class文件中筛选对应于一个依赖对象的class文件;关于所述类标识信息和所述依赖标识信息的说明可参阅上述方法实施例中的相关技术内容描述,在此不再赘述。
在本申请另一些实施例中,所述class文件集合获取模块20具体还用于当所述判断结果不存在对应于一个依赖对象的class文件时,提示操作错误,重新请求新的操作路径,根据新的操作路径获取新的class文件,并判断每个新获取的class文件是否对应于一个依赖对象;通过这种方式可以避免操作路径输入错误导致注入失败的情况。
所述泛型依赖注入模块30用于遍历所述class文件集合,根据所述class文件集合中的每个class文件生成bean对象,将生成的bean对象注入所述目标bean对象的属性中,实现泛型依赖注入;在本实施例中,所述class文件可通过反射和动态代理的方式生成bean对象,关于所述的反射和动态代理的说明可参阅上述方法实施例中的相关技术内容描述,在此不再赘述。
在本申请一些实施例中,所述操作路径获取模块10监听spring容器的启动过程时具体用于在所述spring容器启动的同时开启对所述spring容器的启动过程的监听,直到所述spring容器的启动结束时停止监听。在另一些实施例中,如图3所示,所述spring框架泛型依赖注入装置还可包括计时模块40,所述操作路径获取模块10监听spring容器的启动过程时具体用于在所述spring容器启动的同时调用所述计时模块40开始计时,当所述计时模块40计时达到预设的时长时,所述操作路径获取模块10开启对所述spring容器的启动过程的监听,直到所述spring容器的启动结束时停止监听,这样可以在spring容 器的启动时间较长的情况下不必一直监听而浪费系统资源,当然这种监听方式的前提是能够预估所述spring容器的启动时长或者预先统计过所述spring容器的启动时长,所述计时模块40的计时时长必须低于所述spring容器的启动时长。当然,在实际方案中,所述计时模块40计时的计时时间可根据预估的所述spring容器的启动时长的变化而对应实时调整,保证所述计时模块40的计时时长低于所述spring容器的启动时长即可。
在本申请一些实施例中,在所述泛型依赖注入模块30根据所述class文件集合中的每个class文件生成bean对象之后,所述泛型依赖注入模块30还用于生成各所述bean对象之间的依赖关系,将各所述bean对象之间的依赖关系一并注入所述目标bean对象的属性中。
在本申请一些实施例中,在所述spring容器启动之前,如图3所示,spring框架泛型依赖注入装置还可包括配置模块50,所述配置模块50用于配置所述目标bean对象的操作路径。在本实施例中,所述配置模块50可包括输入入口,通过实时获取输入入口输入的操作路径来实现配置;在另一些实施例中,所述配置模块50也可以通过操作配置文件的方式实现配置。在可实施的方案中,所述配置模块50在进行操作路径的配置过程中,可配置多条操作路径,当所述配置模块50配置有两条以上操作路径时,所述操作路径获取模块10获取所述目标bean对象的操作路径时具体可用于获取配置的全部操作路径,以从多个目标位置中读取class文件;在另一些可实施的方案中,当所述配置模块50配置有两条以上操作路径时,所述操作路径获取模块10获取所述目标bean对象的操作路径时具体可用于根据获取指令中的配置信息从所述两条以上操作路径中获取一条或者几条操作路径。
根据本申请实施例提供的spring框架泛型依赖注入装置,可以应用于自身不具有泛型依赖注入功能的spring框架版本,通过在spring容器启动之后从设定的路径获取class文件来实现泛型依赖注入,这种方式能够简化对象之间的依赖关系,使得程序更加简化,容易阅读,同时侵入性弱,生成的依赖对象在构造完成后可马上进入就绪状态,能有效提高程序运行效率。
本申请实施例还提供一种计算机设备,如图4所示,所述计算机设备包括至少一个处理器401,以及与所述至少一个处理器401通信连接的存储器402,图4中示出一个处理器401,所述存储器402存储有可被所述至少一个处理器401执行的计算机可读指令,所述计算机可读指令被所述至少一个处理器401执行,以使所述至少一个处理器401能够执行如上所述的spring框架泛型依赖注 入方法的步骤。
具体的,本申请实施例中的存储器402为非易失性计算机可读存储介质,可用于存储非易失性软件程序、非易失性计算机可执行程序以及模块,如本申请上述实施例中的spring框架泛型依赖注入方法对应的程序指令/模块;所述处理器401通过运行存储在存储器402中的非易失性软件程序、指令以及模块,从而执行各种功能应用以及进行数据处理,即实现上述方法实施例中所述的spring框架泛型依赖注入方法。
在一些实施例中,所述存储器402可以包括程序存储区和数据存储区,其中,程序存储区可存储操作系统、至少一个功能所需要的应用程序;数据存储区可存储spring框架泛型依赖注入方法的处理过程中所创建的数据等。此外,存储器402可以包括高速随机存取存储器,还可以包括非易失性存储器,例如至少一个磁盘存储器件、闪存器件、或其他非易失性固态存储器件;
在一些实施例中,存储器402可选包括相对于处理器401远程设置的远程存储器,这些远程存储器可以通过网络连接至执行域名过滤处理的计算机设备,前述网络的实例包括但不限于互联网、企业内部网、局域网、移动通信网及其组合。
在本申请实施例中,执行spring框架泛型依赖注入方法的计算机设备还可以包括输入装置403和输出装置4040;其中,输入装置403可获取用户在计算机设备上的操作信息,输出装置4040可包括显示屏等显示设备。在本申请实施例中,所述处理器401、存储器402、输入装置403和输出装置4040可以通过总线或者其他方式连接,图4中以通过总线连接为例。
根据本申请实施例提供的计算机设备,通过处理器401执行存储器402中的代码时能够执行上述实施例中spring框架泛型依赖注入方法的步骤,且具有上述方法实施例的技术效果,未在本实施例中详尽描述的技术细节,可参见本申请方法实施例中所提供的技术内容。
本申请实施例还提供一种非易失性的计算机可读存储介质,所述计算机可读存储介质上存储有计算机可读指令,所述计算机可读指令被至少一个处理器执行时,能够实现如上所述的spring框架泛型依赖注入方法的步骤,当执行所述方法的步骤时,具有上述方法实施例的技术效果,未在本实施例中详尽描述的技术细节,可参见本申请方法实施例中所提供的技术内容。
本申请实施例还提供一种计算机程序产品,所述产品可执行本申请方法实施例中所提供的spring框架泛型依赖注入方法,具备执行方法相应的功能模块 和有益效果。未在本实施例中详尽描述的技术细节,可参见本申请方法实施例中所提供的技术内容。
需要说明的是,在本申请上述实施例中的各功能模块可以集成在一个处理单元中,也可以是各个模块单独物理存在,也可以两个或两个以上模块集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用硬件加软件功能单元的形式实现。
上述以软件功能单元的形式实现的集成的单元,可以存储在一个计算机可读取存储介质中。上述软件功能单元存储在一个存储介质中,包括若干指令用以使得一台计算机装置(可以是个人计算机,服务器,或者网络装置等)或智能终端设备或处理器(Processor)执行本申请各个实施例所述方法的部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储计算机可读指令的介质。
在本申请所提供的上述实施例中,应该理解到,所揭露的装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述模块的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如,两个或以上模块或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。
所述作为分离部件说明的模块可以是或者也可以不是物理上分开的,作为模块显示的部件可以是或者也可以不是物理模块,即可以位于一个地方,或者也可以分布到两个或以上网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。
显然,以上所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例,附图中给出了本申请的较佳实施例,但并不限制本申请的专利范围。本申请可以以许多不同的形式来实现,相反地,提供这些实施例的目的是使对本申请的公开内容的理解更加透彻全面。尽管参照前述实施例对本申请进行了详细的说明,对于本领域的技术人员来而言,其依然可以对前述各具体实施方式所记载的技术方案进行修改,或者对其中部分技术特征进行等效替换。凡是利用本申请说明书及附图内容所做的等效结构,直接或间接运用在其他相关的技术领域,均同理在本申请专利保护范围之内。

Claims (20)

  1. 一种spring框架泛型依赖注入方法,其特征在于,包括:
    监听spring容器的启动过程,在监测到spring容器启动结束后,获取需要进行泛型依赖注入的目标bean对象的操作路径;
    根据所述操作路径从对应的目标位置获取class文件,并判断每个获取的class文件是否对应于一个依赖对象,当判断结果存在对应于一个依赖对象的class文件时,收集对应于一个依赖对象的class文件形成class文件集合;
    遍历所述class文件集合,根据所述class文件集合中的每个class文件生成bean对象,将生成的bean对象注入所述目标bean对象的属性中,实现泛型依赖注入。
  2. 根据权利要求1所述的spring框架泛型依赖注入方法,其特征在于,所述方法还包括:当所述判断结果不存在对应于一个依赖对象的class文件,提示操作错误,重新请求新的操作路径,根据新的操作路径获取新的class文件,并判断每个新获取的class文件是否对应于一个依赖对象。
  3. 根据权利要求1或2所述的spring框架泛型依赖注入方法,其特征在于,所述监听spring容器的启动过程的步骤包括:
    在所述spring容器启动的同时开启对所述spring容器的启动过程的监听;或者在所述spring容器启动的同时开始计时,当计时达到预设的时长时,开启对所述spring容器的启动过程的监听。
  4. 根据权利要求1或2所述的spring框架泛型依赖注入方法,其特征在于,在所述根据所述class文件集合中的每个class文件生成bean对象的步骤之后还包括:
    生成各所述bean对象之间的依赖关系,将所述bean对象之间的依赖关系一并注入所述目标bean对象的属性中。
  5. 根据权利要求1或2所述的spring框架泛型依赖注入方法,其特征在于,在所述spring容器启动之前,所述方法包括:
    配置所述目标bean对象的操作路径;
    其中,当配置有两条以上操作路径时,所述获取需要进行泛型依赖注入的目标bean对象的操作路径包括:获取配置的全部操作路径,或者根据获取指令中的配置信息从所述两条以上操作路径中获取至少一条操作路径。
  6. 根据权利要求1或2所述的spring框架泛型依赖注入方法,其特征在于,所述根据所述class集合中的每个class文件生成bean对象包括:
    根据所述class集合中的每个class文件通过反射和动态代理的方式生成bean对象。
  7. 根据权利要求1或2所述的spring框架泛型依赖注入方法,其特征在于,所述判断每个获取的class文件是否对应于一个依赖对象的步骤包括:
    根据类标识信息确定对应于类的class文件;
    根据依赖标识信息从所述对应于类的class文件中筛选对应于一个依赖对象的class文件。
  8. 一种spring框架泛型依赖注入装置,其特征在于,包括:
    操作路径获取模块,用于监听spring容器的启动过程,在监测到spring容器启动结束后,获取需要进行泛型依赖注入的目标bean对象的操作路径;
    class文件集合获取模块,用于根据所述操作路径从对应的目标位置获取class文件,并判断每个获取的class文件是否对应于一个依赖对象,当判断结果存在对应于一个依赖对象的class文件时,收集对应于一个依赖对象的class文件形成class文件集合;
    泛型依赖注入模块,用于遍历所述class文件集合,根据所述class文件集合中的每个class文件生成bean对象,将生成的bean对象注入所述目标bean对象的属性中,实现泛型依赖注入。
  9. 根据权利要求8所述的spring框架泛型依赖注入装置,其特征在于,所述class文件集合获取模块还用于:当所述判断结果不存在对应于一个依赖对象的class文件,提示操作错误,重新请求新的操作路径,根据新的操作路径获取新的class文件,并判断每个新获取的class文件是否对应于一个依赖对象。
  10. 根据权利要求8或9所述的spring框架泛型依赖注入装置,其特征在于,所述操作路径获取模块监听spring容器的启动过程时具体用于:
    在所述spring容器启动的同时开启对所述spring容器的启动过程的监听;或者在所述spring容器启动的同时开始计时,当计时达到预设的时长时,开启对所述spring容器的启动过程的监听。
  11. 一种计算机设备,其特征在于,包括:
    至少一个处理器;以及,
    与所述至少一个处理器通信连接的存储器;其中,
    所述存储器存储有可被所述至少一个处理器执行的计算机可读指令,所述至少一个处理器执行所述计算机可读指令时实现如下步骤:
    监听spring容器的启动过程,在监测到spring容器启动结束后,获取需要进行泛型依赖注入的目标bean对象的操作路径;
    根据所述操作路径从对应的目标位置获取class文件,并判断每个获取的class文件是否对应于一个依赖对象,当判断结果存在对应于一个依赖对象的class文件时,收集对应于一个依赖对象的class文件形成class文件集合;
    遍历所述class文件集合,根据所述class文件集合中的每个class文件生成bean对象,将生成的bean对象注入所述目标bean对象的属性中,实现泛型依赖注入。
  12. 根据权利要求11所述的计算机设备,其特征在于,所述处理器执行所述计算机可读指令时还实现如下步骤:
    当所述判断结果不存在对应于一个依赖对象的class文件,提示操作错误,重新请求新的操作路径,根据新的操作路径获取新的class文件,并判断每个新获取的class文件是否对应于一个依赖对象。
  13. 根据权利要求11或12所述的计算机设备,其特征在于,所述处理器执行所述计算机可读指令实现所述监听spring容器的启动过程的步骤时,具体实现如下步骤:
    在所述spring容器启动的同时开启对所述spring容器的启动过程的监听;或者在所述spring容器启动的同时开始计时,当计时达到预设的时长时,开启对所述spring容器的启动过程的监听。
  14. 根据权利要求11或12所述的计算机设备,其特征在于,所述处理器执行所述计算机可读指令时还实现如下步骤:
    在所述根据所述class文件集合中的每个class文件生成bean对象的步骤之后,生成各所述bean对象之间的依赖关系,将所述bean对象之间的依赖关系一并注入所述目标bean对象的属性中。
  15. 根据权利要求11或12所述的计算机设备,其特征在于,所述处理器执行所述计算机可读指令实现所述判断每个获取的class文件是否对应于一个依赖对象的步骤时,具体实现如下步骤:
    根据类标识信息确定对应于类的class文件;根据依赖标识信息从所述对应于类的class文件中筛选对应于一个依赖对象的class文件。
  16. 一种非易失性的计算机可读存储介质,其特征在于,所述计算机可读 存储介质上存储有计算机可读指令,所述计算机可读指令被至少一个处理器执行时实现如下的步骤:
    监听spring容器的启动过程,在监测到spring容器启动结束后,获取需要进行泛型依赖注入的目标bean对象的操作路径;
    根据所述操作路径从对应的目标位置获取class文件,并判断每个获取的class文件是否对应于一个依赖对象,当判断结果存在对应于一个依赖对象的class文件时,收集对应于一个依赖对象的class文件形成class文件集合;
    遍历所述class文件集合,根据所述class文件集合中的每个class文件生成bean对象,将生成的bean对象注入所述目标bean对象的属性中,实现泛型依赖注入。
  17. 根据权利要求16所述的非易失性的计算机可读存储介质,其特征在于,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器还执行如下步骤:
    当所述判断结果不存在对应于一个依赖对象的class文件,提示操作错误,重新请求新的操作路径,根据新的操作路径获取新的class文件,并判断每个新获取的class文件是否对应于一个依赖对象。
  18. 根据权利要求16或17所述的非易失性的计算机可读存储介质,其特征在于,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行所述监听spring容器的启动过程的步骤时,具体执行如下步骤:
    在所述spring容器启动的同时开启对所述spring容器的启动过程的监听;或者在所述spring容器启动的同时开始计时,当计时达到预设的时长时,开启对所述spring容器的启动过程的监听。
  19. 根据权利要求16或17所述的非易失性的计算机可读存储介质,其特征在于,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器还执行如下步骤:
    在所述根据所述class文件集合中的每个class文件生成bean对象的步骤之后,生成各所述bean对象之间的依赖关系,将所述bean对象之间的依赖关系一并注入所述目标bean对象的属性中。
  20. 根据权利要求16或17所述的非易失性的计算机可读存储介质,其特征在于,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行所述判断每个获取的class文件是否对应于一个依赖对象的步骤时,具体执行如下步骤:
    根据类标识信息确定对应于类的class文件;根据依赖标识信息从所述对应于类的class文件中筛选对应于一个依赖对象的class文件。
PCT/CN2019/117736 2019-04-23 2019-11-13 spring框架泛型依赖注入方法、装置及计算机设备、存储介质 WO2020215686A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910327704.2A CN110221820B (zh) 2019-04-23 2019-04-23 spring框架泛型依赖注入方法、装置及计算机设备、存储介质
CN201910327704.2 2019-04-23

Publications (1)

Publication Number Publication Date
WO2020215686A1 true WO2020215686A1 (zh) 2020-10-29

Family

ID=67820060

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/117736 WO2020215686A1 (zh) 2019-04-23 2019-11-13 spring框架泛型依赖注入方法、装置及计算机设备、存储介质

Country Status (2)

Country Link
CN (1) CN110221820B (zh)
WO (1) WO2020215686A1 (zh)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114327375A (zh) * 2021-12-27 2022-04-12 上海甄云信息科技有限公司 一种检测java代码依赖关系的方法、工具以及计算机设备
CN118585272A (zh) * 2024-08-02 2024-09-03 湖南长银五八消费金融股份有限公司 一种优先级依赖注入方法及装置、电子设备、存储介质

Families Citing this family (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110221820B (zh) * 2019-04-23 2024-05-28 平安科技(深圳)有限公司 spring框架泛型依赖注入方法、装置及计算机设备、存储介质
CN111427856B (zh) * 2020-03-11 2023-06-02 北京明略软件系统有限公司 一种Java数据的处理方法和装置
CN111381856A (zh) * 2020-03-26 2020-07-07 北京东方国信科技股份有限公司 一种Java软件热更新的方法和装置
CN112256358A (zh) * 2020-10-21 2021-01-22 恒生电子股份有限公司 一种对象控制方法及装置
CN113608725A (zh) * 2021-07-16 2021-11-05 济南浪潮数据技术有限公司 一种对内存数据进行操作的方法、系统、设备及介质
CN113885873B (zh) * 2021-09-29 2022-09-16 中国科学院软件研究所 轻量级OpenHarmony操作系统应用开发对象管理系统及其应用方法
CN116257212A (zh) * 2021-12-10 2023-06-13 北京字节跳动网络技术有限公司 一种基于Hilt实现依赖注入的方法、装置及设备
CN114968395B (zh) * 2022-05-10 2023-09-26 上海淇玥信息技术有限公司 一种基于Spring框架的启动优化方法、装置和计算机设备

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108874464A (zh) * 2018-05-31 2018-11-23 康键信息技术(深圳)有限公司 中间件自动扫描装配方法、装置及存储介质
CN109388403A (zh) * 2018-09-26 2019-02-26 广州视源电子科技股份有限公司 依赖注入方法、装置、设备和存储介质
CN109408569A (zh) * 2018-09-28 2019-03-01 平安科技(深圳)有限公司 Json数据转换方法、装置、计算机设备及存储介质
CN110221820A (zh) * 2019-04-23 2019-09-10 平安科技(深圳)有限公司 spring框架泛型依赖注入方法、装置及计算机设备、存储介质

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102566992B (zh) * 2010-12-17 2015-04-22 卓望数码技术(深圳)有限公司 一种基于系统运行的依赖注入方法及装置
CN102609255B (zh) * 2012-01-19 2015-09-23 中国科学院计算机网络信息中心 一种Spring IOC配置文件的生成方法
CN106648647B (zh) * 2016-12-13 2020-03-24 北京中船信息科技有限公司 基于Spring依赖注入动态创建对象的综合管控系统
CN107239313A (zh) * 2017-06-09 2017-10-10 中国建设银行股份有限公司 Spring应用服务的升级方法和存储介质
KR101987048B1 (ko) * 2017-09-15 2019-06-10 주식회사 티맥스 소프트 자바 플랫폼에서 사용하기 쉬운 형태의 컴파일 시점 의존성 주입 방법 및 장치
CN109254916A (zh) * 2018-08-30 2019-01-22 郑州云海信息技术有限公司 一种基于Spring依赖注入的可视化RestFul接口测试的方法及服务器

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108874464A (zh) * 2018-05-31 2018-11-23 康键信息技术(深圳)有限公司 中间件自动扫描装配方法、装置及存储介质
CN109388403A (zh) * 2018-09-26 2019-02-26 广州视源电子科技股份有限公司 依赖注入方法、装置、设备和存储介质
CN109408569A (zh) * 2018-09-28 2019-03-01 平安科技(深圳)有限公司 Json数据转换方法、装置、计算机设备及存储介质
CN110221820A (zh) * 2019-04-23 2019-09-10 平安科技(深圳)有限公司 spring框架泛型依赖注入方法、装置及计算机设备、存储介质

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
SINGH, ADITYA ET AL.: "Formulating an MVC Framework for Web Development in JAVA", PROCEEDINGS OF THE 2ND INTERNATIONAL CONFERENCE ON TRENDS IN ELECTRONICS AND INFORMATICS (ICOEI 2018), 12 May 2018 (2018-05-12), XP033460472, DOI: 20200117181416A *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114327375A (zh) * 2021-12-27 2022-04-12 上海甄云信息科技有限公司 一种检测java代码依赖关系的方法、工具以及计算机设备
CN118585272A (zh) * 2024-08-02 2024-09-03 湖南长银五八消费金融股份有限公司 一种优先级依赖注入方法及装置、电子设备、存储介质

Also Published As

Publication number Publication date
CN110221820A (zh) 2019-09-10
CN110221820B (zh) 2024-05-28

Similar Documents

Publication Publication Date Title
WO2020215686A1 (zh) spring框架泛型依赖注入方法、装置及计算机设备、存储介质
US8719784B2 (en) Assigning runtime artifacts to software components
CN105183457B (zh) 一种监听界面生命周期回调的方法及装置
US7882492B2 (en) Intelligent computer program debugger, and system and method for implementing the same
US9665475B2 (en) Application experiment system
US9626276B2 (en) Generating a test version of a method to be called during runtime and fulfilling a collaboration contract
US8745598B2 (en) Running injected code prior to execution of an application
EP2204739A1 (en) Defining a conditional breakpoint
US9003231B1 (en) System for instantiating service instances for testing in a known state
US20160357535A1 (en) System and method for importing and exporting an integration flow in a cloud-based integration platform
US9824000B1 (en) Testing calling code dynamically with random error injection based on user-specified configuration
CN115422063A (zh) 一种低代码接口自动化系统、电子设备及存储介质
CN111880804A (zh) 应用程序代码的处理方法及装置
JP2012530297A (ja) ソフトウェアコンポーネント状態に対するアクセスコントロール
Bocic et al. Symbolic model extraction for web application verification
WO2015196805A1 (zh) 批命令的执行方法及装置
US20210182412A1 (en) System and method for managing data object creation
US11182131B2 (en) System and method that support production management
CN107506299B (zh) 一种代码分析方法及终端设备
US20170139577A1 (en) User interface development in a transcompiling environment
CN111858037B (zh) 一种物理机的服务编排方法、装置、设备及存储介质
US7987210B1 (en) System for lightweight objects
US20060036999A1 (en) System and method for managing test and measurement components
CN106598687A (zh) 一种脚本预热方法和装置
US11381662B2 (en) Transition of business-object based application architecture via dynamic feature check

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19926222

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19926222

Country of ref document: EP

Kind code of ref document: A1