From 5fb3f591678235803d9c60b29dc9adafbcc30aa6 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期一, 17 一月 2022 22:15:09 +0800
Subject: [PATCH] 优化代码

---
 java110-service/src/test/java/com/java110/service/smo/impl/QueryServiceSMOImplTest.java |   35 ++++++++++++++++++++++++++++++-----
 1 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/java110-service/src/test/java/com/java110/service/smo/impl/QueryServiceSMOImplTest.java b/java110-service/src/test/java/com/java110/service/smo/impl/QueryServiceSMOImplTest.java
old mode 100644
new mode 100755
index 5cbbce3..eaf3fa2
--- a/java110-service/src/test/java/com/java110/service/smo/impl/QueryServiceSMOImplTest.java
+++ b/java110-service/src/test/java/com/java110/service/smo/impl/QueryServiceSMOImplTest.java
@@ -1,14 +1,15 @@
 package com.java110.service.smo.impl;
 
-
 import javassist.CannotCompileException;
-import javassist.ClassClassPath;
 import javassist.ClassPool;
 import javassist.CtClass;
 import javassist.CtMethod;
 import javassist.CtNewMethod;
+import javassist.NotFoundException;
+import javassist.util.HotSwapper;
 import junit.framework.TestCase;
 
+import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -16,25 +17,49 @@
 public class QueryServiceSMOImplTest extends TestCase {
 
 
-    public void testJava() throws CannotCompileException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+    public void testJava() throws CannotCompileException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, NotFoundException, IOException, ClassNotFoundException {
         String javaCode = "public static void testJava2() {       DataQuery dataQuery = new DataQuery();\n dataQuery.setServiceCode(\"鏈嶅姟缂栫爜\");  System.out.println(dataQuery.getServiceCode());\n}\n";
                 String    javaCode2 ="public static void testJava1() {     testJava2(); ServiceSql serviceSql = new ServiceSql();  System.out.println(\"623213\");\n}";
+                String    javaCode3 ="public static void testJava3() {     ServiceSql serviceSql = new ServiceSql();  System.out.println(\"723213\");\n}";
         ClassPool classPool = ClassPool.getDefault();
         classPool.importPackage("com.java110.entity.service.DataQuery");
         classPool.importPackage("com.java110.entity.service.ServiceSql");
-        CtClass ctClass = classPool.makeClass("com.java110.service.smo.WuxwTest");
+        CtClass ctClass = classPool.makeClass("com.java110.service.smo.WuxwTest3");
         CtMethod helloM = CtNewMethod.make(javaCode, ctClass);
         ctClass.addMethod(helloM);
 
         CtMethod helloM1 = CtNewMethod.make(javaCode2, ctClass);
         ctClass.addMethod(helloM1);
-        Class pc=ctClass.toClass();
+        Class<?> pc=ctClass.toClass();
+        //ctClass.writeFile("./1111");
         Method move= pc.getMethod("testJava1",new Class[]{});
 
         Constructor<?> con=pc.getConstructor(new Class[]{});
 
         move.invoke(con);
 
+        CtClass ctClass2 = classPool.get("com.java110.service.smo.WuxwTest3");
+        CtMethod helloM3 = CtNewMethod.make(javaCode3, ctClass2);
+        ctClass2.addMethod(helloM3);
+        //ctClass.detach();
+
+       // CtClass ctClass3 = classPool.get("com.java110.service.smo.WuxwTest1");
+
+        /*HotSwapper swap = new HotSwapper(8000);
+        swap.reload("com.java110.service.smo.WuxwTest3",ctClass2.toBytecode());
+        Class ctClass1 = Class.forName("com.java110.service.smo.WuxwTest3");
+
+
+         move= ctClass1.getMethod("testJava3",new Class[]{});
+
+         con=ctClass1.getConstructor(new Class[]{});
+
+        move.invoke(con);*/
+
+
+
+
+
 
 
     }

--
Gitblit v1.8.0