大神们关于javassist 动态编译的问题

//ClassPool:CtClass对象的容器

ClassPool pool = ClassPool.getDefault();

    //通过ClassPool生成一个public新类Emp.java    
    CtClass ctClass = pool.makeClass("javassist.demo.MyCC");    



    //添加自定义方法    
    CtMethod ctMethod = new CtMethod(CtClass.voidType,"printInfo",new CtClass[]{},ctClass);    
    //为自定义方法设置修饰符    
    ctMethod.setModifiers(Modifier.PUBLIC);    
    //为自定义方法设置函数体    
    StringBuffer buffer2 = new StringBuffer();    
    buffer2.append("{\nSystem.out.println(\"begin!\");\n")    

            .append("}");    
    ctMethod.setBody(buffer2.toString());    
    ctClass.addMethod(ctMethod);    

            执行以下代码报错 
            ctClass.toClass(); 

            大神求解决

            Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
StackWalker cannot be resolved to a type
StackWalker cannot be resolved to a type
StackWalker cannot be resolved
StackWalker cannot be resolved to a variable
StackWalker cannot be resolved to a type
StackWalker cannot be resolved to a type
The method dropLookupMode(int) is undefined for the type MethodHandles.Lookup
The method defineClass(byte[]) is undefined for the type MethodHandles.Lookup

at javassist.util.proxy.DefineClassHelper$SecuredPrivileged$3.<init>(DefineClassHelper.java:53)
at javassist.util.proxy.DefineClassHelper$SecuredPrivileged.<clinit>(DefineClassHelper.java:38)
at javassist.util.proxy.DefineClassHelper.<clinit>(DefineClassHelper.java:177)
at javassist.ClassPool.toClass(ClassPool.java:1120)
at javassist.ClassPool.toClass(ClassPool.java:1083)
at javassist.ClassPool.toClass(ClassPool.java:1041)
at javassist.CtClass.toClass(CtClass.java:1278)
at javassist.demo.GenerateNewClassByJavassist.main(GenerateNewClassByJavassist.java:46)

1个回答

stackwalker是个第三方类
不知道你说的是不是这个
http://blog.sina.com.cn/s/blog_648d306d0100qmca.html

caoheike
caoheike javassist
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Python+OpenCV计算机视觉

Python+OpenCV计算机视觉

关于javassist重复加载的问题

最近需要使用javassist动态改变类里的方法,问题是javassist使用过一次以后,第二次使用就会冻结,可是在第二次就算用了解冻,调用toclass以后还是会报异常,主要是为了得到frmAttributesI的实体,怎样已经冻结的class解冻之后还可以继续编辑修改并调用呢? String body = null; CtClass cc = null; IFrmAttributes frmAttributesI = null; //从数据查找判断是否是二次加载 String isCondUpdate = "Y"; if(isClassInit == false){ //第一次调用 // 获取所有条件信息(执行脚本) ClassPool pool = ClassPool.getDefault(); //导入相关jar包 pool.importPackage("java.util.Hashtable"); pool.importPackage("java.util.List"); pool.importPackage("java.util.Date"); pool.importPackage("java.text.SimpleDateFormat"); // 在外部变量执行类中,动态加载外部变量执行算法 cc = pool.get("com.process.FrmAttributes"); CtMethod cm = cc.getDeclaredMethod("process"); //cc.defrost(); System.out.println("测试1=================="+body.toString()); cm.setBody("{" + body.toString() + "}"); Class c = cc.toClass(); frmAttributesI = (FrmAttributes) c.newInstance(); this.isClassInit = true; }else{ if(isCondUpdate == "Y"){ frmAttributesI = null; ClassPool pool2 = ClassPool.getDefault(); cc = pool2.get("com.process.FrmAttributes"); if(cc.isFrozen()){ cc.defrost(); } //删除方法,增加方法,试试二次加载 //第二次调用 CtMethod cm2 = cc.getDeclaredMethod("process"); System.out.println("测试2============================"+body.toString()); cm2.setBody("{" + body.toString() + "}"); cc.writeFile(); Class c = cc.toClass(); frmAttributesI = (FrmAttributes) c.newInstance(); } }

javassist能动态改变方法的返回对象么?

在mybatis3的MappedStatement类中有个public BoundSql getBoundSql(Object parameterObject)方法,我希望该方法在运行时返回我生成的BoundSql 对象而不是这个方法原生的对象。javassist能行么。我在网上摘了些代码运行不过去 [code="java"] // 用于取得字节码类,必须在当前的classpath中,使用全称 CtClass ctClass = ClassPool.getDefault().get("org.apache.ibatis.mapping.MappedStatement"); // 需要修改的方法名称 String mname = "getBoundSql"; CtMethod mold = ctClass.getDeclaredMethod(mname); // 修改原有的方法名称 String nname = mname + "$impl"; mold.setName(nname); // 创建新的方法,复制原来的方法 CtMethod mnew = CtNewMethod.copy(mold, mname, ctClass, null); // 主要的注入代码 StringBuffer body = new StringBuffer(); body.append("{return "+newBoundSql); // 调用原有代码,类似于method();($$)表示所有的参数 //body.append(nname + "($$);\n"); //body.append("System.out.println(\"Call to method " + mname + " took \" +\n (System.currentTimeMillis()-start) + " + "\" ms.\");\n"); body.append("}"); // 替换新方法 mnew.setBody(body.toString()); // 增加新方法 ctClass.addMethod(mnew); return (MappedStatement) ctClass.toClass().newInstance(); [/code]

javassist hibernate 应用问题

需求: 1、当服务启动时,根据hbm.xml动态创建相应的pojo,并不是生成.java或.class,是用javassist动态创建的。(已经完成) 2、根据前台请求,先修改对应的hbm.xml,用的是dom4j,然后动态去修改前面动态生成的pojo,这个也是用javassist改的,但是在修改的最后,toClass()的时候抛出异常,说是存在同一个类。这时候我就没有继续toClass(),然后用ClassPool获得了修改后的pojo,检测了一下修改的情况,确实是修改好了,添加上了该添加的字段。这时候,相应的hbm.xml和pojo都已经修改好了,按说如果我重新rebuildsession后,再用hql查询这个pojo的话,对应动态添加的这个字段应该是null。 这时候问题出现了: 我查询出的pojo仍然是以前未修改的那个,新生成的字段并没有出现。并且我在hibernate.cfg.xml里面配置了<property name="hbm2ddl.auto">update</property>,按道理数据库的表中也应该自动生成相应的字段,这时候也没有生成。 我分析是我动态修改的类没有和session再次绑定,所以session里面还是以前的那个类;第二,数据库表没有生成相应的字段,就是因为configuration.configure(filename)好像带了缓存,它根本就不读修改后的hbm.xml(这个我做了个实验,在运行时我把hbm.xml删了,可是没反应)。 我想不出办法解决,请诸位帮忙,谢谢!

javassist一个很奇怪的问题

采用javassist来将一个类中的field改变类型。待改变的类代码如下: [code="java"]public class JassistTest { @Autowired private StpService stpService; public void doit(Long userid){ PeakSeasonMainResponse res = stpService.getPeakOverView(userid); System.out.println(stpService.getClass().getName()); System.out.println("hello" + res); } }[/code] 进行改变操作的类如下: [code="java"]public class TestMain { public TestMain(){ } public static void main(String[] args) throws Exception{ ClassPool pool = ClassPool.getDefault(); CtClass cc = pool.get("JassistTest"); CtField f = cc.getDeclaredField("stpService"); cc.removeField(f); cc.addField(CtField.make("private Proxy stpService;", cc)); cc.writeFile("D:\\DevProgram\\eclipse-jee-kepler-R-win32\\workspace\\stable\\fc-deimos\\target\\test-classes"); JassistTest test = new JassistTest(); test.doit(7060L); } } [/code] class文件生成后,我用反编译工具查看,Javassist已经变为如下: [code="java"]public class JassistTest { private Proxy stpService; public void doit(Long userid) { PeakSeasonMainResponse res = this.stpService.getPeakOverView(userid); System.out.println(this.stpService.getClass().getName()); System.out.println("hello" + res); } }[/code] 但当我执行TestMain.java文件中的test.doit()方法时,还是报异常了。 [code="java"]Exception in thread "main" java.lang.NoSuchFieldError: stpService at JassistTest.doit(JassistTest.java:13) at TestMain.main(TestMain.java:33) [/code] 实在搞不懂,请教大家

使用javassist创建一个类出现了javassist.CannotCompileException这个异常

1.看的尚学堂的java300集敲代码报错在网上找很久没找到答案 2.下面是代码 public class JavassistTest01 { /** * 测试使用javassist生成一个新的类 * @param args * @throws CannotCompileException * @throws NotFoundException */ public static void main(String[] args) throws Exception { ClassPool pool=ClassPool.getDefault(); CtClass cc=pool.makeClass("home04.Emp"); //创建属性 CtField f1=CtField.make("private int empno", cc); CtField f2=CtField.make("private String ename", cc); cc.addField(f1); cc.addField(f2); cc.writeFile("c:/MyJava");//将构造好的类写入到工作空间下 System.out.println("生成类成功!"); } } 3.下面是报错信息 Exception in thread "main" javassist.CannotCompileException: [source error] syntax error near " int empno" at javassist.CtField.make(CtField.java:173) at home04.JavassistTest01.main(JavassistTest01.java:23) Caused by: compile error: syntax error near " int empno" at javassist.compiler.Parser.parseField(Parser.java:111) at javassist.compiler.Parser.parseMember1(Parser.java:87) at javassist.compiler.Javac.compile(Javac.java:98) at javassist.CtField.make(CtField.java:168) ... 1 more 第一次提问,希望有人看到解答

使用javassist实现动态修改注解,在tomcat下无法获取class路径

public ExcelBean createExcelBean(String[] propertyArray, String[] typeArray, String[] columnNameArray) throws NotFoundException, CannotCompileException, InstantiationException, IllegalAccessException { ExcelBean excelBean = null; ClassPool pool = ClassPool.getDefault(); //在tomcat环境下,向pool插入一个类对象的搜索路径 pool.insertClassPath("com.camb.common.web.bean.ExcelBean"); //获取要修改的类 CtClass ctClass = pool.get("com.camb.common.web.bean.ExcelBean"); for (int i = 0; i < propertyArray.length; i++) { //生成属性以及get和set方法 String property = propertyArray[i]; String method = property.substring(0, 1).toUpperCase() + property.substring(1, property.length()); String type = typeArray[i]; String column = columnNameArray[i]; ctClass.addField(CtField.make("private " + type + " " + property + ";", ctClass)); ctClass.addMethod(CtMethod.make("public void set" + method + "(" + type + " " + property + "){this." + property + " = " + property + ";}", ctClass)); ctClass.addMethod(CtMethod.make("public " + type + " get" + method + "(){return this." + property + ";}", ctClass)); //获取类里的属性 CtField ctField = ctClass.getField(property); FieldInfo fieldInfo = ctField.getFieldInfo(); System.out.println("属性名:" + ctField.getName()); ConstPool cp = fieldInfo.getConstPool(); //获取注解信息 AnnotationsAttribute attribute = new AnnotationsAttribute(cp, AnnotationsAttribute.visibleTag); Annotation annotation = new Annotation("com.camb.common.web.util.Excel", cp); //修改名称为name的注解 annotation.addMemberValue("name", new StringMemberValue(column, cp)); attribute.setAnnotation(annotation); fieldInfo.addAttribute(attribute); //打印修改后注解 Annotation annotation2 = attribute.getAnnotation("com.camb.common.web.util.Excel"); String value = ((StringMemberValue) annotation2.getMemberValue("name")).getValue(); System.out.println("修改后的注解参数===" + value); } //修改后的class Class<?> c = ctClass.toClass(); excelBean = (ExcelBean) c.newInstance(); ctClass.detach(); return excelBean; } pool.insertClassPath("com.camb.common.web.bean.ExcelBean");这个设置并不能找到class的位置,如果使用pool.insertClassPath(new ClassClassPath(ExcelBean.class));虽然能找class,但是会产生异常 com.camb.common.web.exception.ProcessException: javassist.CannotCompileException: by java.lang.LinkageError: loader (instance of org/apache/catalina/loader/WebappClassLoader): attempted duplicate class definition for name: "com/camb/common/web/bean/ExcelBean"

关于javassist的一些API参数的疑问

``` ClassPool pool = ClassPool.getDefault(); CtClass cc = pool.get("test.Emp"); CtMethod m = new CtMethod(CtClass.intType, "add", new CtClass[]{CtClass.intType}, cc); m.setModifiers(Modifier.PUBLIC); m.setBody("{return n;}"); cc.addMethod(m); ``` 这个包下有很多这样的API,CtMethod里的前面的参数我都明白是对方法的描述,但最后一个参数我不清楚有什么用,它并没有把方法写进cc里,又对方法的定义没作用。

javassist修改字节码的逻辑, 应该在项目运行的哪一步执行?

最近用javassist修改了mybatis中获取连接池中的连接的逻辑做了一点修改; javassist是在项目编译成class文件之后, javassist对class文件中的方法进行修改,那这一段修改class文件逻辑应该加在什么地方呢?有大神帮忙看一下吗, 谢谢

解决Usage: java javassist.tools.web.Webserver \<port number\>问题

在起动服务器得时候会出现这个页面![图片说明](https://img-ask.csdn.net/upload/201910/28/1572264931_971350.png) 点击ok之后会报Usage: java javassist.tools.web.Webserver \<port number\> 我这个项目使用springboot整合SSM得 这个问题该如何解决?

如何使用java agent+ javassist获得目标方法的参数值?

http://blog.csdn.net/supera_li/article/details/45846175 看了一片博客,对agent会了,但是具体的怎么用javassist获得方法的参数值或者是方法内部的属性值?

使用动态代理生成的对象如何动态注入到spring容器?

使用动态代理生成的对象如何动态注入到spring? 如同mybatis的mapper接口自动生成代理类,亦如同spring data jpa生成接口实现类, 自己写了demo使用@Bean可以将生成的动态代理对象注入到spring容器,但无法动态的注入,求解?

cannot be cast to javassist.util.proxy.Proxy

这是我的代码结构: ![图片说明](https://img-ask.csdn.net/upload/201703/21/1490089343_799107.png) 代码下载地址(好像贴不完,有字数要求,麻烦了):http://pan.baidu.com/s/1cDzTAA 运行TestM2O时报错: INFO: HHH000327: Error performing load command : org.hibernate.HibernateException: HHH000142: Javassist Enhancement failed: entity.Grade 三月 21, 2017 5:43:35 下午 org.hibernate.event.internal.DefaultLoadEventListener doOnLoad INFO: HHH000327: Error performing load command : org.hibernate.HibernateException: HHH000142: Javassist Enhancement failed: entity.Grade Exception in thread "main" org.hibernate.HibernateException: HHH000142: Javassist Enhancement failed: entity.Grade at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:130) at org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:717) at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:4580) at org.hibernate.event.internal.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:359) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:274) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1142) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1025) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:639) at org.hibernate.type.EntityType.resolve(EntityType.java:431) at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:165) at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:125) at org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.performTwoPhaseLoad(AbstractRowReader.java:238) at org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.finishUp(AbstractRowReader.java:209) at org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:133) at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:122) at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:86) at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:167) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4069) at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:508) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:478) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1142) at org.hibernate.internal.SessionImpl.access$2600(SessionImpl.java:167) at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.doLoad(SessionImpl.java:2762) at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2741) at org.hibernate.internal.SessionImpl.get(SessionImpl.java:978) at test.TestM2O.findGradeByStudent(TestM2O.java:37) at test.TestM2O.main(TestM2O.java:14) Caused by: java.lang.ClassCastException: entity.Grade_$$_javassist_0 cannot be cast to javassist.util.proxy.Proxy at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:123) ... 32 more 如果我把student.hbm.xml中的<many-to-one>标签删除就可以运行,不知道为什么,大家能帮我解答一下吗,我用的是hibernate5.1.5

使用ClassPool生成代理类 报错javassist.CannotCompileException

javassist.CannotCompileException: [source error] TryTest(com.asp.eb.TestPacket) not found in java.lang.Object 代码是这样的: ClassPool pool = ClassPool.getDefault(); pool.insertClassPath(new ClassClassPath(clazz)); CtClass oldClass = pool.get(clazz.getName()); CtClass ct = pool.makeClass(new StringBuffer().append(oldClass.getName()).append("$Proxy").toString()); CtClass superCt = pool.get(HttpPacketHandler.class.getName()); ct.addInterface(superCt); StringBuffer sb = new StringBuffer("public void handle (com.asp.eb.TestPacket packet)throws Exception{"); sb.append("int code = $1.getPacketId();"); sb.append("switch(code){"); Iterator ite =opMethods.entrySet().iterator(); while(ite.hasNext()){ Map.Entry entry = (Map.Entry)ite.next(); sb.append("case ").append(entry.getKey()).append(":"); sb.append("super.").append((String)entry.getValue()).append("($$);"); sb.append("break;"); opcodes.add(((Integer)entry.getKey()).intValue()); } sb.append("}"); sb.append("}"); System.out.println("----------------------------------------"); System.out.println(sb.toString()); System.out.println("----------------------------------------"); CtMethod method = CtMethod.make(sb.toString(),ct);

大神帮忙看看这是什么问题?

![图片说明](https://img-ask.csdn.net/upload/201709/11/1505095911_340439.png) 第一个错不需要看主要是第二个错 我调的别的公司的接口传进去了数值,现在因为人家数据库中没有数据,所以给我返回了个null,这说明接口应该是调用成功了,我想知道第二个错误是不是因为我没有数据所以报错?我在后台判断接口的数据如果是null前端页面就会弹一个弹窗,现在弹窗成功了,这个错误是因为没有数据吧?

IDEA下Tomcat控制台总报这个错,各位大神帮帮忙,怎么解决,这个问题已经困扰很久了

SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.startup.ContextConfig.processAnnotationsJar Unable to process Jar entry [javassist/tools/reflect/CannotInvokeException.class] from Jar [jar:file:/D:/IDEA_WORKING/wolfkill/target/wolfkill/WEB-INF/lib/javassist-3.20.0-GA.jar!/] for annotations java.io.EOFException at java.io.DataInputStream.readUnsignedShort(DataInputStream.java:340) at org.apache.tomcat.util.bcel.classfile.Utility.swallowMethodParameters(Utility.java:187) at org.apache.tomcat.util.bcel.classfile.Attribute.readAttribute(Attribute.java:159) at org.apache.tomcat.util.bcel.classfile.FieldOrMethod.<init>(FieldOrMethod.java:76) at org.apache.tomcat.util.bcel.classfile.ClassParser.readMethods(ClassParser.java:226) at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:101) at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:1987) at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1940) at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1915) at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1876) at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1145) at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:767) at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:302) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117) at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5083) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714) at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1588) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:463) at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:413) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468) at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309) at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401) at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:324) at sun.rmi.transport.Transport$1.run(Transport.java:200) at sun.rmi.transport.Transport$1.run(Transport.java:197) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:196) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) 07-Dec-2017 20:08:27.159 SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.startup.ContextConfig.processAnnotationsJar Unable to process Jar entry [javassist/tools/reflect/CannotReflectException.class] from Jar [jar:file:/D:/IDEA_WORKING/wolfkill/target/wolfkill/WEB-INF/lib/javassist-3.20.0-GA.jar!/] for annotations java.io.EOFException

jbpm4发布问题--pdversion类型转换错误

在整合好s2sh后,把jbpm也整合进来成功了,第一次发布流程成功,当停止了tomcat服务后,再次发布相同的流程时就会报一个错误:java.lang.String cannot be cast to java.lang.Long, at org.jbpm.pvm.internal.repository.DeploymentImpl.getProcessDefinitionVersion(DeploymentImpl.java:225),看了原码,确实是有一个类型转换,在取了pdversion后,强制转换成Long,可就找不到问题所在,后来直接到数据库的JBPM4_DEPLOYPROP表把字段为key_列的所有pdversion去掉,然后再次发布也能成功,但流程的版本是第一,感觉这个pdvesion有问题,但解决不了,这问题纠结了很久,搞得蛋都要碎了,哎,高手们,求助,求助啊!! ---------------------------------- 错误的部分信息: 信息: exception while executing command org.jbpm.pvm.internal.query.ProcessDefinitionQueryImpl@5a7ff7 java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long at org.jbpm.pvm.internal.repository.DeploymentImpl.getProcessDefinitionVersion(DeploymentImpl.java:225) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:197) at org.jbpm.pvm.internal.repository.DeploymentImpl_$$_javassist_59.getProcessDefinitionVersion(DeploymentImpl_$$_javassist_59.java) at org.jbpm.pvm.internal.repository.ProcessDeployer.deploy(ProcessDeployer.java:86) at org.jbpm.pvm.internal.repository.DeployerManager.deploy(DeployerManager.java:46) at org.jbpm.pvm.internal.repository.RepositorySessionImpl.getObject(RepositorySessionImpl.java:130) at org.jbpm.pvm.internal.query.ProcessDefinitionQueryImpl.getProcessDefinition(ProcessDefinitionQueryImpl.java:92) at org.jbpm.pvm.internal.query.ProcessDefinitionQueryImpl.execute(ProcessDefinitionQueryImpl.java:80) at org.jbpm.pvm.internal.query.AbstractQuery.execute(AbstractQuery.java:83) -----------------------------------------------------------------------

问下各位大神,我刚学Hibernate,下载是我的第一个代码,为什么老链接报错,希望大神们解答一下

1.持久化类代码: package Model; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistryBuilder; //开发持久化类 public class Connec_Base { private SessionFactory sessionFactory; private Session session; private Transaction trancaction; private Configuration conf; private ServiceRegistry serviceRegister; public void init(){ //创建配置对象 try { conf = new Configuration().configure(); } catch (HibernateException e) { System.out.println("创建配置对象失败"); e.printStackTrace(); } //创建服务注册对象 try { // serviceRegister = new StandardServiceRegistryBuilder(). // applySettings(conf.getProperties()).build(); serviceRegister=new ServiceRegistryBuilder().applySettings(conf.getProperties()).buildServiceRegistry(); } catch (Exception e) { System.out.println("创建服务注册对象失败"); e.printStackTrace(); } System.out.println(serviceRegister); try { //创建会话工厂对象 sessionFactory=conf.buildSessionFactory(serviceRegister); } catch (HibernateException e) { System.out.println("创建会话工厂对象失败"); e.printStackTrace(); } //会话对象 session=sessionFactory.openSession(); //开启事物 trancaction=session.beginTransaction(); } public void Destory(){ //开启事物 trancaction.commit(); //关闭会话 session.close(); //关闭会话工厂 sessionFactory.close(); } public void add(Student s){ init(); session.save(s); Destory(); } } 2.hibernate.cfg.xml代码: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/text?useUnicode=true&amp;characterEncoding=UTF-8</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">ch2738</property> <!-- 显示sql语句 --> <property name="hibernate.show_sql">true</property> <!-- 自动创建表格 --> <property name="hibernate.hbm2ddl.auto">true</property> <!-- 方言:为每一种数据库提供适配器,方便转换 --> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <mapping resource="Model/Student.hbm.xml"/> </session-factory> </hibernate-configuration> 3.Student.hbm.xml代码 <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Generated 2016-10-19 21:31:10 by Hibernate Tools 3.5.0.Final --> <hibernate-mapping> <class name="Student" table="STUDENT"> <id name="id" type="java.lang.String"> <column name="ID" /> <generator class="assigned" /> </id> <property name="name" type="java.lang.String"> <column name="NAME" /> </property> <property name="school" type="java.lang.String"> <column name="SCHOOL" /> </property> </class> </hibernate-mapping> ![代码结构图](https://img-ask.csdn.net/upload/201610/19/1476887581_62092.png) 3报错信息 十月 19, 2016 10:34:49 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit> INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final} 十月 19, 2016 10:34:49 下午 org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {4.3.11.Final} 十月 19, 2016 10:34:49 下午 org.hibernate.cfg.Environment <clinit> INFO: HHH000206: hibernate.properties not found 十月 19, 2016 10:34:49 下午 org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist 十月 19, 2016 10:34:49 下午 org.hibernate.cfg.Configuration configure INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml 十月 19, 2016 10:34:49 下午 org.hibernate.cfg.Configuration getConfigurationInputStream INFO: HHH000040: Configuration resource: /hibernate.cfg.xml 十月 19, 2016 10:34:49 下午 org.hibernate.cfg.Configuration addResource INFO: HHH000221: Reading mappings from resource: Model/Student.hbm.xml 十月 19, 2016 10:34:50 下午 org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide! 十月 19, 2016 10:34:50 下午 org.hibernate.cfg.Configuration doConfigure INFO: HHH000041: Configured SessionFactory: null org.hibernate.boot.registry.internal.StandardServiceRegistryImpl@184f6be2 十月 19, 2016 10:34:50 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!) 十月 19, 2016 10:34:50 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://127.0.0.1:3306/text?useUnicode=true&characterEncoding=UTF-8] 十月 19, 2016 10:34:50 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH000046: Connection properties: {user=root, password=****} 十月 19, 2016 10:34:50 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH000006: Autocommit mode: false 十月 19, 2016 10:34:50 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000115: Hibernate connection pool size: 20 (min=1) 创建会话工厂对象失败 org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator$1$1.convert(BasicConnectionCreator.java:122) at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:140) at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:58) at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:75) at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:106) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206) at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260) at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206) at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845) at Model.Connec_Base.init(Connec_Base.java:38) at Model.Connec_Base.add(Connec_Base.java:59) at Model.text.main(text.java:7) Caused by: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:943) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4113) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1308) at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2336) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2369) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2153) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305) at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:55) ... 15 more Exception in thread "main" java.lang.NullPointerException at Model.Connec_Base.init(Connec_Base.java:44) at Model.Connec_Base.add(Connec_Base.java:59) at Model.text.main(text.java:7)

关于怎样修改jar包里面的.class 文件并重新打包的问题?

我有个jar包是写的surfaceView的信息,但我想修改这个类,就用解压软件解压后,用jd-jui软件打开,将这个类复制到text文件中修改后,想编译一下再放入jar中,但是编译不了我用javac view.java 提示找不到这个类引入的其他类,请问各位大侠该怎样做,您的帮助,永远感激!

2019 Python开发者日-培训

2019 Python开发者日-培训

150讲轻松搞定Python网络爬虫

150讲轻松搞定Python网络爬虫

设计模式(JAVA语言实现)--20种设计模式附带源码

设计模式(JAVA语言实现)--20种设计模式附带源码

YOLOv3目标检测实战:训练自己的数据集

YOLOv3目标检测实战:训练自己的数据集

java后台+微信小程序 实现完整的点餐系统

java后台+微信小程序 实现完整的点餐系统

三个项目玩转深度学习(附1G源码)

三个项目玩转深度学习(附1G源码)

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

2019 AI开发者大会

2019 AI开发者大会

玩转Linux:常用命令实例指南

玩转Linux:常用命令实例指南

一学即懂的计算机视觉(第一季)

一学即懂的计算机视觉(第一季)

4小时玩转微信小程序——基础入门与微信支付实战

4小时玩转微信小程序——基础入门与微信支付实战

Git 实用技巧

Git 实用技巧

Python数据清洗实战入门

Python数据清洗实战入门

使用TensorFlow+keras快速构建图像分类模型

使用TensorFlow+keras快速构建图像分类模型

实用主义学Python(小白也容易上手的Python实用案例)

实用主义学Python(小白也容易上手的Python实用案例)

程序员的算法通关课:知己知彼(第一季)

程序员的算法通关课:知己知彼(第一季)

MySQL数据库从入门到实战应用

MySQL数据库从入门到实战应用

机器学习初学者必会的案例精讲

机器学习初学者必会的案例精讲

手把手实现Java图书管理系统(附源码)

手把手实现Java图书管理系统(附源码)

极简JAVA学习营第四期(报名以后加助教微信:eduxy-1)

极简JAVA学习营第四期(报名以后加助教微信:eduxy-1)

.net core快速开发框架

.net core快速开发框架

玩转Python-Python3基础入门

玩转Python-Python3基础入门

Python数据挖掘简易入门

Python数据挖掘简易入门

微信公众平台开发入门

微信公众平台开发入门

程序员的兼职技能课

程序员的兼职技能课

Windows版YOLOv4目标检测实战:训练自己的数据集

Windows版YOLOv4目标检测实战:训练自己的数据集

HoloLens2开发入门教程

HoloLens2开发入门教程

微信小程序开发实战

微信小程序开发实战

Java8零基础入门视频教程

Java8零基础入门视频教程

Python可以这样学(第一季:Python内功修炼)

Python可以这样学(第一季:Python内功修炼)

相关热词 c#跨线程停止timer c#批量写入sql数据库 c# 自动安装浏览器 c#语言基础考试题 c# 偏移量打印是什么 c# 绘制曲线图 c#框体中的退出函数 c# 按钮透明背景 c# idl 混编出错 c#在位置0处没有任何行
立即提问