An agile development method and medium based on java dynamic agent
Through the agile development method based on Java dynamic proxy, the problems of difficulty in maintaining code and low credit efficiency in existing systems are solved, and the rapid implementation of partner business and efficient credit are achieved.
Patent Information
- Application Number
- CN202111521213.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-13
- Publication Date
- 2025-02-21
- Estimated Expiration
- 2041-12-13
AI Technical Summary
The existing bank's intranet Jiedai pre-system and similar Internet Jiedai pre-system based on open code platforms have problems such as difficulty in maintaining code, complex changes, and long maintenance, and cannot adapt to customers' efficient credit needs in the Internet environment.
Adopt agile development method based on Java dynamic proxy, and obtain and store dynamic proxy class code strings configured by partner business through compiled program modules, and call business delegation classes based on these code strings through call program modules to achieve rapid cooperation business Dead.
It implements the implementation of high and low versions of Java, with execution efficiency consistent with native Java code, easy-to-maintain code, and can quickly complete business implementation, reducing the workload of developers' intervention and regression testing.
Smart Images

Figure CN114327400B_ABST
Abstract
Description
[Technical field]
[0001] The present invention relates to the technical field of computer software, and in particular to an agile development method and medium based on java dynamic agent. [Background technology]
[0002] The existing intranet quick loan front-end system of banks and similar online quick loan front-end systems based on open code platforms generally have difficulties in code maintenance, complex changes, and long maintenance time. There is weak security verification in the process and it is unable to adapt to the Internet environment and provide efficient credit to customers.
[0003] The Agricultural Bank of China requires that the branch optimize the customer acquisition channels of the front-end scenarios of "Net Express Loan" (Zhuye Kuai e Loan, the same below) to realize online customer acquisition, pre-credit and other functions. The customer logs in to the loan application interface embedded in the third-party platform of the Agricultural Bank of China, and the branch system realizes the functions of automatic pre-credit investigation, review and approval, feedback and "Net Express Loan" whitelist import. For this business, as a branch, it is necessary to respond quickly to the access of scenario-based business on the premise that the head office system provides the final import pre-credit whitelist and credit inquiry interface. After the main body of the branch system is developed, the access partners mainly need to add different configurations of each partner to the two modules of system whitelist and credit formula.
[0004] At a time when system, change, and security management are becoming increasingly stringent, ordinary software changes must necessarily start from the demand stage, and developers need to perform design, coding, unit testing, system testing, regression testing, production launch, special care, etc. Considering that business line personnel do not have time or are not technically skilled, they cannot directly configure the functional modules required by partners through the management end, and developers are required to perform simple design, coding, and unit testing. Therefore, it is necessary to save developers the access process after unit testing to achieve rapid implementation of the business.
[0005] The existing mainstream dynamic languages, such as groovy (a scripting language based on JVM), have a certain learning cost; JEP (java expression parser) can only implement simple formulas for low-version java, but cannot implement complex function call logic; or implement function operations in SQL, but consume precious database connection resources; for example, the ScriptEngineManager provided in high-version java is less efficient than the native one when running Python, and is more than twice as slow as the native one when running JS.
[0006] Agile development focuses on the evolution of user needs and adopts an iterative and step-by-step approach to software development. In agile development, software projects are divided into multiple sub-projects at the beginning of construction. The results of each sub-project are tested and have the characteristics of being visible, integrable, and operational. In other words, a large project is divided into multiple small projects that are interconnected but can also be run independently, and they are completed separately. During this process, the software is always in a usable state.
[0007] The API (Application Programming Interface) in Java is a set of predefined functions that aims to provide applications and developers with the ability to access a set of routines based on certain software or hardware without having to access the source code or understand the details of the internal working mechanism. The SPI mechanism in Java, SPI stands for Service Provider Interface, is a service provider discovery mechanism built into the JDK. In simple terms, it is a dynamic replacement discovery mechanism, which is actually a dynamic loading mechanism implemented by combining "interface-based programming + strategy mode + configuration file".
[0008] The proxy pattern is a commonly used Java design pattern. Its characteristic is that the proxy class has the same interface as the delegate class. The proxy class is mainly responsible for pre-processing messages for the delegate class, filtering messages, forwarding messages to the delegate class, and post-processing messages. There is usually an association relationship between the proxy class and the delegate class. An object of a proxy class is associated with an object of a delegate class. The object of the proxy class itself does not actually implement the service, but provides specific services by calling the relevant methods of the object of the delegate class. Simply put, when accessing the actual object, it is accessed through the proxy object. The proxy pattern introduces a certain degree of indirection when accessing the actual object, because this indirection can be added with multiple uses. According to the time point of creating the proxy class, it is divided into static proxy and dynamic proxy. The key to the implementation of dynamic proxy in Java is: Proxy (agent program) and InvocationHandler (invocation handler), among which InvocationHandler (invocation handler) implements dynamic proxy through the invoke method in the InvocationHandler interface.
[0009] The present invention makes technical improvements to an agile development method for realizing rapid business implementation based on Java dynamic proxy. [Summary of the invention]
[0010] The purpose of the present invention is to provide an agile development method that is adaptable to high and low versions of Java, has execution efficiency consistent with native Java code, is easy to maintain code, and realizes rapid business implementation.
[0011] To achieve the above-mentioned purpose, the technical solution adopted by the present invention is an agile development method based on Java dynamic proxy, based on a compiler module for accepting, storing and compiling a code string of a partner business configuration dynamic proxy class, and a calling program module for calling a business delegation class according to the partner business configuration dynamic proxy class to implement the partner business implementation; the compiler module performs the following steps:
[0012] S1. Get a Java compiler JavaCompiler;
[0013] S2. Get a standard Java file manager StandardJavaFileManager;
[0014] S3. Initialize a custom Java file manager MyForwardingJavaFileManager, receive the standardFileManager object as a parameter through the constructor, encapsulate a custom class file object ClassJavaFileObject, which is used to accept the partner's business configuration dynamic proxy class code string;
[0015] S4. Initialize a custom Java source file object MySimpleJavaFileObject to store the partner business configuration dynamic proxy class code string into a Java source file;
[0016] S5. Based on the custom Java source file object MySimpleJavaFileObject and the custom Java file manager MyForwardingJavaFileManager, the dynamic proxy class code string of the partner business configuration is received and stored;
[0017] S6. Get the JavaCompiler.CompilationTask instance from the JavaCompiler instance;
[0018] S7, using the JavaCompiler.CompilationTask instance to execute the compilation task of the partner business configuration dynamic proxy class obtained in step S5;
[0019] The calling program module performs the following steps:
[0020] S8. According to the scenario number of the partner, based on the custom java source file object MySimpleJavaFileObject and the custom java file manager MyForwardingJavaFileManager, retrieve the code string of the dynamic proxy class for the partner's business configuration;
[0021] S9. Initialize the custom class loader MyClassLoader;
[0022] S10. Load the partner's business configuration dynamic proxy class based on the custom class loader MyClassLoader. The class name is consistent with the dynamic proxy class name transmitted by the partner.
[0023] S11. Based on the invoke method in the Java dynamic proxy InvocationHandler interface, the dynamic proxy class calls the business delegation class according to the partner's business configuration to implement the partner's business.
[0024] Preferably, the partner business configuration dynamic proxy class code string obtained in step S5 includes a program code string for implementing the partner business based on the business delegation class; step S11 calls the program for implementing the partner business based on the business delegation class.
[0025] Preferably, the partner business configuration dynamic proxy class refers to a dynamic proxy class in the bank's quick e-loan front-end system that performs loan approval based on customer information provided by the partner, or a dynamic proxy class in the programming competition system that performs programming exams based on the identities of contestants provided by the partner, or a dynamic proxy class in the Java training-oriented education system that assigns homework based on the identities of students provided by the partner.
[0026] Preferably, step S3 customizes the Java file manager MyForwardingJavaFileManager, inherits the parent class ForwardingJavaFileManager; encapsulates a ClassJavaFileObject to customize the class file type attribute classJavaFileObject, encapsulates a getClassJavaFileObject method for externally calling the classJavaFileObject attribute, and returns the customized class file object.
[0027] Preferably, step S4 customizes the java source file class MySimpleJavaFileObject, inherits the parent class SimpleJavaFileObject, and encapsulates a source file content attribute; while calling the constructor of the custom java source file class MySimpleJavaFileObject and the constructor of the parent class SimpleJavaFileObject, assigns the "dynamic code" string to the parameter content attribute, overrides the getCharContent method of the parent class, and returns the content string; inputs the "dynamic code" string by externally calling the constructor of the custom java source file class MySimpleJavaFileObject.
[0028] Preferably, in step S3, a custom class file type ClassJavaFileObject is defined, which inherits the parent class SimpleJavaFileObject and encapsulates a byte array output stream of type ByteArrayOutputStream; the byte array output stream creates a byte array buffer in memory, and all data sent to the byte array output stream is stored in the byte array buffer; when the constructor of the custom class file type ClassJavaFileObject is called, the constructor of the parent class is called, and a byte array output stream of a ByteArrayOutputStream object is initialized at the same time; the openOutputStream method in the parent class is rewritten to return the byte array output stream of the ByteArrayOutputStream object, which is used for calling the custom class loader MyClassLoader in step S10.
[0029] Preferably, in step S9, the custom class loader MyClassLoader inherits the parent class ClassLoader and encapsulates a custom class file type ClassJavaFileObject; when calling the construction method of the custom class loader MyClassLoader, the parameters are assigned to the custom class file type attributes.
[0030] Preferably, the dynamic class code management terminal program module accepts the management partner scenario number, the partner business configuration dynamic proxy class code string, and the information required for the business configuration.
[0031] Preferably, the dynamic class code management terminal program module is based on the vue software framework.
[0032] Another object of the present invention is to provide an agile development medium that is adaptable to high and low versions of Java, has execution efficiency consistent with native Java code, is easy to maintain code, and realizes rapid business implementation.
[0033] To achieve the above-mentioned another object, the technical solution adopted by the present invention is a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the above-mentioned agile development method based on Java dynamic agent is implemented.
[0034] The invention discloses an agile development method and medium based on java dynamic proxy, which has the following beneficial effects: 1. It solves the difficulty of code maintenance. When external partners are constantly accessing, only the class or method related to the current access is updated. Through configuration, the code string is compiled once by the management end, and then it can be called without changing the main system code, so that the access process is completed efficiently, and the access of the partner can be completed without the intervention of the original developer; 2. The maintenance of the code is not limited to IDE (Integrated Development Environment IDE), and the code can be changed by logging in to the management end through a web editor, which greatly reduces the regression testing workload required for traditional system changes; 3. Since it is not necessary to store the class file compiled by dynamic coding on the server end, it is particularly suitable for application scenarios such as the bank's fast e-loan front-end system (the function of granting loans according to customer information provided by the partner), the programming competition system (the function of taking programming tests according to the identity of the contestants provided by the partner) or the education system in the direction of java training (the function of assigning homework according to the identity of the trainees provided by the partner).
Brief Description of the Drawings
[0035] Figure 1 This is a business flow chart of a certain fast e-loan front-end system.
[0036] Figure 2 It is a flow chart of an agile development method based on Java dynamic proxy to quickly implement partner business. [Specific implementation method]
[0037] The present invention will be further described below in conjunction with embodiments and with reference to the accompanying drawings.
[0038] Example
[0039] This embodiment implements an agile development method based on Java dynamic proxy to quickly implement partner business, and is applied to the agile development of a certain fast e-loan front-end system.
[0040] Figure 1 This is a business flow chart of a certain fast e-loan front-end system. Figure 1As shown, this embodiment is an agile development method for quickly implementing partner business based on java dynamic proxy. Its position in a certain Kuai E loan front-end system is located within the thick-lined box. Its main function is to accept and save the loan customer information and image data pushed by the Kuai E loan partner. For the Kuai E loan business, on the premise that the head office system provides the final import pre-credit whitelist and credit inquiry interface, each branch needs to respond quickly to the access of scenario-based business. After the main body of the Kuai E loan front-end system of each branch is developed, when the partner software is accessed, it is necessary to add different configurations for each partner to the two modules of system whitelist and credit formula. In general, because the business line personnel do not have time or are not from a technical background, they cannot directly configure the functional modules required by the partner through the management end, and developers are required to perform simple design, coding, and unit testing.
[0041] The present embodiment is an agile development method for quickly implementing partner services based on Java dynamic proxy. It is used to add different configurations for each partner to the system whitelist and credit formula modules when the partner software is accessed. The execution efficiency is consistent with that of native Java code. Through configuration, the code string is compiled once using the management end and can be called in the system. This saves developers the need to perform simple design, coding, and unit testing when accessing the "partner software adds different configurations for each partner to the system whitelist and credit formula modules" after unit testing, so as to quickly implement the fast e-loan business.
[0042] Figure 2 This is a flow chart of an agile development method based on Java dynamic proxy to quickly implement partner business. Figure 2 As shown, the text description of the process of an agile development method based on java dynamic proxy to realize the rapid implementation of partner business in this embodiment is as follows: Get a java compiler JavaCompiler, get a customized java file manager MyForwardingJavaFileManager, get a customized java file object MySimpleJavaFileObject, and then you can get the JavaCompiler.CompilationTask instance from the JavaCompiler instance, and then the JavaCompiler.CompilationTask instance is used to execute the corresponding compilation task. This execution process is a concurrent process. After the compilation task is executed, load the compiled class object, get the method object, execute this method, and get the return Object object of the method. Since the object is used to splice XML messages later, there is no need to convert the object type. If you need to perform other processes, you can convert the return object into the required type as needed.
[0043] The core dynamic proxy class configuration function of the agile development method based on Java dynamic proxy to realize the rapid implementation of partner business in this embodiment includes the following program modules:
[0044] Program Module 0: System Whitelist and Credit Formula
[0045] As attached Figure 1 As shown, this implementation implements an agile development method based on Java dynamic proxy to quickly implement partner business. After receiving the customer information message sent by the partner server, it enters the system whitelist module to determine whether this partner meets the access conditions.
[0046] The system whitelist refers to the partner scenario whitelist. Each scenario has the following characteristics:
[0047] 1. Partner scenario number: 01-99 is used to distinguish different scenarios corresponding to partners. A partner can use multiple scenario numbers to call different credit formulas, multi-IP access, and call back notification services of each partner.
[0048] 2. Partner IP whitelist array: ["ip1", "ip2"] multiple source IP addresses of a partner. When receiving a message, find its IP whitelist by scenario ID. If it is not in the whitelist, return access denied.
[0049] 3. Credit formula class string: The following code string classString2 is the credit formula class code string of a certain automobile decoration partner.
[0050] private static String classString2=
[0051] "import java.text.DecimalFormat; import work.formula.LoanModelDAO;"
[0052] +"public class LoanModel123{"
[0053] +"public String do04(LoanModelDAO loanModelDAO){"
[0054] +"DecimalFormat decimalFormat=new DecimalFormat(\"#\");"
[0055] +"Double bankPerAmount=null;"
[0056] +"Double lastHalfYearMonthOrder=loanModelDAO.getRentSalePer();"
[0057] +"Double lastYearMonthOrder=loanModelDAO.getYearSaleIncome();"
[0058] +"if(lastHalfYearMonthOrder>=lastYearMonthOrder){"
[0059] +"bankPerAmount=loanModelDAO.getRentSalePer()*12*2*0.1;"
[0060] +"return decimalFormat.format(bankPerAmount);"
[0061] +"}"
[0062] +"else{"
[0063] +"return\"eeee\";"
[0064] +"}"
[0065] +"}"
[0066] +"}";
[0067] Function of the credit formula class code string classString2: When receiving the customer information message sent by the partner server, find the credit formula class code string corresponding to different scenarios through the scenario number. This formula class is the core of this embodiment - the dynamic proxy class. This dynamic proxy class is not compiled at the same time as other classes of the system, but is configured as a string using the management end, and dynamic compilation is achieved through this embodiment.
[0068] The credit formula class code string classString2 function obtains the pre-credit data field through the credit data entity class, and calculates the branch credit limit: Taking the code string classString2 as an example, first initialize a number formatting tool DecimalFormat decimalFormat, and define the data format to retain the integer. Get the customer's "first half of the year average monthly order amount lastHalfYearMonthOrder" data from the LoanModelDAO credit data entity class mentioned below, and then get the customer's "last year average monthly income lastYearMonthOrder" data. If the average monthly order amount is greater than or equal to the average monthly income, an error is directly returned to the partner, and the customer does not meet the admission conditions. On the contrary, the average monthly income of the previous year multiplied by 12 (months) multiplied by 2 (coefficient 1) multiplied by 0.1 (coefficient 2) to get the branch credit limit, and return the integer obtained by formatting the branch credit limit.
[0069] Method do04 in the class provides loans based on customer information. The credit data entity class of its parameter object, that is, the entrustment class, is as follows:
[0070]
[0071]
[0072] Function of the credit data entity class (delegate class): In the credit formula class code string (dynamic proxy class) of each partner, it is stipulated that a unified parameter type should be used, namely the credit data entity class (delegate class) - LoanModelDAO class.
[0073] Credit data entity class (delegation class) function: As shown in the credit data entity class (delegation class) code above, the LoanModelDAO class processes the pre-credit data fields contained in the customer information message sent by the partner server. All partner credit formulas use the following fields:
[0074] 1. private Double rentSalePer; / / pre-credit condition data 1
[0075] 2. private Double yearSaleIncome; / / Average monthly income in the previous year
[0076] 3. private Double monthRent; / / Pre-credit condition data 2
[0077] 4. private Double custCreditAmount; / / Customer expected amount
[0078] 5. private Double loanPeriod; / / Loan period (months)
[0079] 6. private String partnerName; / / Partner scenario code
[0080] Pre-credit condition data 1 includes data types such as rental-to-sale ratio, average monthly order amount in the first half of the year, etc.
[0081] Pre-credit condition data 2 includes data types such as monthly rent, average monthly store sales, etc.
[0082] These two fields are relatively flexible. You can enter different types according to different scenarios, but you need to coordinate with your partners in advance to determine the type of data. The calculation method is determined by the credit formula code string (dynamic proxy class).
[0083] The construction method defines the process of processing the above pre-credit data fields from the incoming message from the partner: get the value of each field from the map object, if it is empty or null, assign it to 0. Then define the setter and getter methods to facilitate the modification and acquisition of these pre-credit data when calling from the outside. The getter method is mainly used in the dynamic class to obtain the credit data required by each formula.
[0084] The callback partner service address URL is used to notify the partner of the pre-credit limit obtained by the customer.
[0085] Program module 1: compile java code string
[0086] JavaCompiler is an interface for calling the Java programming language compiler from a program.
[0087] The compiler may generate diagnostic information (e.g., error messages) during compilation. If a diagnostic listener is provided, the diagnostics are provided to the listener. If no listener is provided, the diagnostics are formatted in an unspecified format and written to the default output, which is System.err unless otherwise specified. Even if a diagnostic listener is provided, some diagnostics may not be appropriate for diagnosis and will be written to the default output.
[0088] A compiler tool has an associated standard file manager, which is the native (or built-in) file manager for that tool. The standard file manager can be obtained by calling getStandardFileManager.
[0089] The compiler tool must work with any file manager as long as any other requirements detailed in the following methods are met. If no file manager is provided, the compiler tool uses a standard file manager, such as the one returned by getStandardFileManager.
[0090] Instances that implement this interface must conform to the Java Language Specification and generate class files that conform to the Java Virtual Machine Specification. The versions of these specifications are defined in the tool interface. In addition, instances of this interface that support SourceVersion.RELEASE_6 or higher must also support annotation processing.
[0091] The compiler depends on two services: diagnostic listeners and file managers. Although most of the classes and interfaces in this package define APIs for the compiler (and general tools), the interfaces DiagnosticListener, JavaFileManager, FileObject, and JavaFileObject are not intended to be used in applications. Instead, these interfaces are intended to be implemented and used to provide custom services to the compiler, thus defining an SPI for the compiler.
[0092] There are a number of classes and interfaces in this package that are designed to simplify the implementation of the SPI to customize the behavior of the compiler: StandardJavaFileManager Every compiler that implements this interface provides a standard file manager for operating regular files. The StandardJavaFileManager interface defines additional methods for creating file objects from regular files.
[0093] The code is as follows:
[0094] / / Get the Java compiler
[0095] JavaCompiler compiler=ToolProvider.getSystemJavaCompiler();
[0096] StandardJavaFileManager standardFileManager=compiler.getStandardFileManager(null,null,null);
[0097] The parameters of the getStandardFileManager method are:
[0098] diagnosticListener The diagnostic listener to use for non-fatal diagnostics; if null, the compiler's default method for reporting diagnostics is used;
[0099] locale The locale to be applied when formatting diagnostics; null indicates the default locale;
[0100] charset The character set to use to decode the bytes; if null the platform default is used.
[0101] Then initialize a custom Java file manager object (described in detail below):
[0102] MyForwardingJavaFileManager classJavaFileManager=newMyForwardingJavaFileManager(standardFileManager);
[0103] Initialize a java source file object (described in detail below):
[0104] MySimpleJavaFileObject stringObject=new MySimpleJavaFileObject(newURI("LoanModel123.java"),JavaFileObject.Kind.SOURCE,classString2);
[0105] The parameters are:
[0106] File URI (this is the name of the source file, but the file will not actually be stored on the server);
[0107] Java file type (specified as source file);
[0108] A string of code in a source file (i.e. dynamically entered code).
[0109] The interface representing the compilation task. However, the compilation task has not yet started. If you need to start the task, you need to call the call method.
[0110] CompilationTask task=compiler.getTask(null,classJavaFileManager,null,null,null,Arrays.asList(stringObject));
[0111] task.call()
[0112] At this point, the dynamic code has been compiled into a .class file, but the .class file is not stored locally. It is then converted into binary through outputStream for calling.
[0113] Program module 2: Calling the method in the compiled class
[0114] Get the custom class file object from the custom Java file manager (described in detail below):
[0115] ClassJavaFileObject javaFileObject=classJavaFileManager.getClassJavaFileObject();
[0116] Initialize the custom class loader:
[0117] ClassLoader classLoader=new MyClassLoader(javaFileObject);
[0118] The parameter is the above file-like object.
[0119] Loading class:
[0120] Object loanModel=classLoader.loadClass("LoanModel123").newInstance();
[0121] The class name is consistent with the source file name and is consistent with the java xx specification when executing javac xx.java in the command line of native java.
[0122] Get the method in the class:
[0123] Method do04=loanModel.getClass().getMethod("do04",LoanModelDAO.class);
[0124] The parameters are:
[0125] 1. Method name;
[0126] 2. The type of method parameters.
[0127] Calling the method:
[0128] Object invoke=do04.invoke(loanModel,new LoanModelDAO(190.0,124.0,121.0,121.0,121.0));
[0129] The parameters are:
[0130] 1. Methods;
[0131] 2. Specific parameters of the method input.
[0132] The result returned after the call is of type Object. Since the object is used to splice XML messages, this system does not need to convert the object type. If other processes are required, the returned object can also be converted into any required type as needed.
[0133] Program module 3: Custom java file management class
[0134]
[0135]
[0136] As shown in the code, this embodiment customizes a Java file management class MyForwardingJavaFileManager, which inherits ForwardingJavaFileManager. It encapsulates a custom class type attribute classJavaFileObject of ClassJavaFileObject. It encapsulates a getClassJavaFileObject method for externally calling the classJavaFileObject attribute and returning a custom class file object. At the same time, the constructor of this class calls the constructor of its parent class ForwardingJavaFileManager.
[0137] Program module 4: Custom Java source file class
[0138]
[0139] As shown in the code, this embodiment customizes a java source file class and inherits the parent class SimpleJavaFileObject. This class encapsulates a source file content attribute. When calling the constructor of this class, the constructor of the parent class is called, and the third parameter "dynamic code" of the constructor of this class is assigned to the content attribute. Override the getCharContent method of the parent class to return the content string. If the constructor is called externally, it can be completed to read the content of a file named xx.java even if it does not exist, and the parent class will not report an error. Its content is the parameter "content" string that we input when calling the construction method. In this way, a java source file object is obtained.
[0140] Program Module 5: Custom class file class
[0141]
[0142]
[0143] As shown in the code, this embodiment defines a class file class, which also inherits the parent class SimpleJavaFileObject. This class encapsulates a byte array output stream of type ByteArrayOutputStream. The byte array output stream creates a byte array buffer in memory, and all data sent to the output stream is stored in the byte array buffer.
[0144] When calling the constructor of this class, a ByteArrayOutputStream object is initialized at the same time as calling the constructor of the parent class.
[0145] Override the openOutputStream method in the parent class to return a ByteArrayOutputStream object for subsequent custom class loader calls.
[0146] Program Module 6: Custom Class Loader
[0147]
[0148] As shown in the code, this embodiment customizes a custom class loader class and inherits the parent class ClassLoader. It encapsulates a property of the ClassJavaFileObject type (the custom class file class mentioned above). When calling the constructor, the parameter is assigned to the defined class file attribute. The findClass method is rewritten to convert the custom class file into binary. In this way, when the MyClassLoader class is called externally, even if there is no file named xx.class in the file system, the findClass method can convert the custom class file into binary instead, and the return parameter of the defineClass method of the parent class becomes the binary code of the custom class, without reporting an error that the xx class (xx.class) does not exist.
[0149] Program Module 7: Dynamic Class Code Management Terminal Page
[0150] The dynamic code management page uses the vue framework, which is a progressive JavaScript framework for building user interfaces.
[0151] Specific implementation:
[0152] 1. First, you need to execute the command npminstall ace-builds-S to install dependencies;
[0153] 2. Create a file named dynamicCodeEditor.vue. The specific page code has no relevance to the main body of the embodiment and will not be described here.
[0154] Specific use:
[0155] 1. Introduce it into the page and register the component;
[0156] import CodeEditor from'@ / components / CodeEditor'
[0157] 2. Use;
[0158] <code-editor ref="_firstRefs"class="editor h-100"v-model="editorContent"readonly language="json"theme="dracula">
[0159] Among them, editorContent is the two-way binding editor content.
[0160] The agile development method for quickly implementing partner services based on Java dynamic proxy in this embodiment can also be used in programming competition systems (providing programming test functions), or in programming tests in education systems with Java training orientation (providing homework functions).
[0161] A person skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0162] The above is only a preferred embodiment of the present invention. It should be pointed out that ordinary technicians in this technical field can make several improvements and supplements without departing from the principle of the present invention. These improvements and supplements should also be regarded as the scope of protection of the present invention.
Claims
1. An agile development method based on Java dynamic proxy, characterized in that: Based on a compiler module for accepting, storing and compiling a code string of a dynamic proxy class for partner business configuration, and a calling program module for calling a business delegation class according to the dynamic proxy class for partner business configuration to implement partner business implementation; the compiler module performs the following steps: S1. Get a Java compiler JavaCompiler; S2. Get a standard Java file manager StandardJavaFileManager; S3. Initialize a custom Java file manager MyForwardingJavaFileManager, receive the standardFileManager object as a parameter through the constructor, encapsulate a custom class file object ClassJavaFileObject, which is used to accept the partner's business configuration dynamic proxy class code string; S4. Initialize a custom Java source file object MySimpleJavaFileObject to store the partner business configuration dynamic proxy class code string into a Java source file; S5. Based on the custom Java source file object MySimpleJavaFileObject and the custom Java file manager MyForwardingJavaFileManager, the dynamic proxy class code string of the partner business configuration is received and stored; S6. Get the JavaCompiler.CompilationTask instance from the JavaCompiler instance; S7, using the JavaCompiler.CompilationTask instance to execute the compilation task of the partner business configuration dynamic proxy class obtained in step S5; The calling program module performs the following steps: S8. According to the scenario number of the partner, based on the custom java source file object MySimpleJavaFileObject and the custom java file manager MyForwardingJavaFileManager, retrieve the code string of the dynamic proxy class for the partner's business configuration; S9. Initialize the custom class loader MyClassLoader; S10. Load the partner's business configuration dynamic proxy class based on the custom class loader MyClassLoader. The class name is consistent with the dynamic proxy class name transmitted by the partner. S11. Based on the invoke method in the Java dynamic proxy InvocationHandler interface, the dynamic proxy class calls the business delegation class according to the partner's business configuration to implement the partner's business.
2. According to claim 1, an agile development method based on Java dynamic agent is characterized in that: The partner business configuration dynamic proxy class code string obtained in step S5 includes a program code string for implementing the partner business based on the business delegation class; step S11 calls the program for implementing the partner business based on the business delegation class.
3. The agile development method based on Java dynamic agent according to claim 1, characterized in that: The partner business configuration dynamic proxy class refers to the dynamic proxy class in the bank's quick e-loan front-end system that performs loan approval based on customer information provided by the partner, or the dynamic proxy class in the programming competition system that performs programming exams based on the identity of contestants provided by the partner, or the dynamic proxy class in the Java training-oriented education system that assigns homework based on the identity of students provided by the partner.
4. The agile development method based on Java dynamic proxy according to claim 1, characterized in that: Step S3 customizes the Java file manager MyForwardingJavaFileManager, inherits the parent class ForwardingJavaFileManager; encapsulates a ClassJavaFileObject to customize the class file type attribute classJavaFileObject, encapsulates a getClassJavaFileObject method for externally calling the classJavaFileObject attribute, and returns the customized class file object.
5. The agile development method based on Java dynamic proxy according to claim 4, characterized in that: Step S4 defines a custom Java source file class MySimpleJavaFileObject, inherits the parent class SimpleJavaFileObject, and encapsulates a source file content attribute; while calling the constructor of the custom Java source file class MySimpleJavaFileObject and the constructor of the parent class SimpleJavaFileObject, assigns the "dynamic code" string to the parameter content attribute, overrides the getCharContent method of the parent class, and returns the content string; inputs the "dynamic code" string by externally calling the constructor of the custom Java source file class MySimpleJavaFileObject.
6. The agile development method based on Java dynamic proxy according to claim 5, characterized in that: In step S3, a custom class file type ClassJavaFileObject is defined, which inherits the parent class SimpleJavaFileObject and encapsulates a byte array output stream of type ByteArrayOutputStream; the byte array output stream creates a byte array buffer in memory, and all data sent to the byte array output stream is stored in the byte array buffer; when the constructor of the custom class file type ClassJavaFileObject is called, the constructor of the parent class is called, and a byte array output stream of a ByteArrayOutputStream object is initialized at the same time; the openOutputStream method in the parent class is rewritten to return the byte array output stream of the ByteArrayOutputStream object, which is used for calling the custom class loader MyClassLoader in step S10.
7. The agile development method based on Java dynamic proxy according to claim 6, characterized in that: Step S9: The custom class loader MyClassLoader inherits the parent class ClassLoader and encapsulates a custom class file type ClassJavaFileObject; when calling the construction method of the custom class loader MyClassLoader, the parameters are assigned to the custom class file type attributes.
8. The agile development method based on Java dynamic proxy according to claim 1, characterized in that: Based on the dynamic class code management terminal program module, the management partner scenario number, the partner business configuration dynamic proxy class code string, and the information required for business configuration are accepted.
9. The agile development method based on Java dynamic proxy according to claim 8, characterized in that: The dynamic class code management terminal program module is based on the vue software framework.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the agile development method based on Java dynamic agent described in any one of claims 1 to 9 is implemented.
Citation Information
Patent Citations
Java-platform-based web service support method and device
CN102929597A
A code compilation generation tool based on dynamic compilation and a dynamic compilation method
CN109947430A