波总:
创建一个普通的maven工程,其中某个类为 com.jfinal.handler.Handler的子类,如图
使用 jfinal_demo_for_maven工程,引入外部jar包
使用如下
启动报错:
Starting JFinal 4.8 -> http://0.0.0.0:80 Info: jfinal-undertow 2.0, undertow 2.0.28.Final, jvm 1.8.0_131 Exception in thread "main" java.lang.VerifyError: Bad type on operand stack Exception Details: Location: com/demo/common/DemoConfig.configHandler(Lcom/jfinal/config/Handlers;)V @8: invokevirtual Reason: Type 'com/sl/jfinal/swagger/handler/SwaggerValidatorHandler' (current frame, stack[1]) is not assignable to 'com/jfinal/handler/Handler' Current Frame: bci: @8 flags: { } locals: { 'com/demo/common/DemoConfig', 'com/jfinal/config/Handlers' } stack: { 'com/jfinal/config/Handlers', 'com/sl/jfinal/swagger/handler/SwaggerValidatorHandler' } Bytecode: 0x0000000: 2bbb 0026 59b7 0027 b600 2857 b1 at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at com.jfinal.core.JFinalFilter.createJFinalConfig(JFinalFilter.java:126) at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:61) at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:111) at io.undertow.servlet.core.ManagedFilter.createFilter(ManagedFilter.java:80) at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:591) at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:556) at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42) at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43) at io.undertow.servlet.core.DeploymentManagerImpl.start(DeploymentManagerImpl.java:598) at com.jfinal.server.undertow.UndertowServer.configHttp(UndertowServer.java:284) at com.jfinal.server.undertow.UndertowServer.doStart(UndertowServer.java:262) at com.jfinal.server.undertow.UndertowServer.start(UndertowServer.java:159) at com.jfinal.server.undertow.UndertowServer.start(UndertowServer.java:84) at com.demo.common.DemoConfig.main(DemoConfig.java:34) Process finished with exit code 1
如果这么使用,又是正常的
请问是怎么回事?
项目:JFinal
undertow.hotSwapClassPrefix=com.sl.jfinal.
也可以这么来配置:
UndertowServer.create(MyApp.class)
.addHotSwapClassPrefix("com.sl.jfinal.")
.start();
这里有文档:
https://jfinal.com/doc/1-5
原因是,jfinal undertow 默认只对 target/classes 以及 jfinal 做了 hotSwap ,从而 jfinal 与 target/classes 采用的是 HotSwapClassLoader
而你的 com.sl.jfinal. 下面的类 SwaggerValidatorHandler 继承了 jfinal 中的某些组件,但并未使用 HotSwapClassLoader 进行类加载,从而造成类型不对
这种类型不对,表面上看不出来,是因为它们被不同的 ClassLoader 所加载