异常:javassist.CannotCompileException: [source error] getPropertyValue

由于在 dubbo 接口服务中添加了一个接口,之后项目运行出现如下异常信息:

java.lang.IllegalStateException: Failed to load ApplicationContext

    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
    at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:189)
    at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:131)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.RuntimeException: [source error] getPropertyValue (Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object; in com.alibaba.dubbo.common.bytecode.Wrapper4: inconsistent stack height -1
    at com.alibaba.dubbo.common.bytecode.ClassGenerator.toClass(ClassGenerator.java:303)
    at com.alibaba.dubbo.common.bytecode.ClassGenerator.toClass(ClassGenerator.java:257)
    at com.alibaba.dubbo.common.bytecode.Wrapper.makeWrapper(Wrapper.java:239)
    at com.alibaba.dubbo.common.bytecode.Wrapper.getWrapper(Wrapper.java:101)
    at com.alibaba.dubbo.rpc.proxy.javassist.JavassistProxyFactory.getInvoker(JavassistProxyFactory.java:40)
    at com.alibaba.dubbo.rpc.proxy.wrapper.StubProxyFactoryWrapper.getInvoker(StubProxyFactoryWrapper.java:104)
    at com.alibaba.dubbo.rpc.ProxyFactory$Adaptive.getInvoker(ProxyFactory$Adaptive.java)
    at com.alibaba.dubbo.config.ServiceConfig.exportLocal(ServiceConfig.java:542)
    at com.alibaba.dubbo.config.ServiceConfig.doExportUrlsFor1Protocol(ServiceConfig.java:499)
    at com.alibaba.dubbo.config.ServiceConfig.doExportUrls(ServiceConfig.java:367)
    at com.alibaba.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:324)
    at com.alibaba.dubbo.config.ServiceConfig.export(ServiceConfig.java:221)
    at com.alibaba.dubbo.config.spring.ServiceBean.onApplicationEvent(ServiceBean.java:135)
    at com.alibaba.dubbo.config.spring.ServiceBean.onApplicationEvent(ServiceBean.java:50)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:393)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:347)
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:883)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
    at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:120)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
    ... 24 more
Caused by: javassist.CannotCompileException: [source error] getPropertyValue (Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object; in com.alibaba.dubbo.common.bytecode.Wrapper4: inconsistent stack height -1
    at javassist.CtNewMethod.make(CtNewMethod.java:79)
    at javassist.CtNewMethod.make(CtNewMethod.java:45)
    at com.alibaba.dubbo.common.bytecode.ClassGenerator.toClass(ClassGenerator.java:282)
    ... 49 more
Caused by: compile error: getPropertyValue (Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object; in com.alibaba.dubbo.common.bytecode.Wrapper4: inconsistent stack height -1
    at javassist.compiler.Javac.compile(Javac.java:104)
    at javassist.CtNewMethod.make(CtNewMethod.java:74)
    ... 51 more

由于在添加接口之前,一切都是正常的,因此可以排除 dubbo 版本问题,在网上查找资料说可能是由于提供的接口以 getXXX 开头,而且接口没有返回值,从而出现此种异常。因此试着先把问题给解决了,就按文章说的,把接口名称给改了,不以 get 开头,经验证,确实是此原因。那么为什么会有这么奇怪的现象出现呢?查看了下 dubbo 源码,dubbo 动态生成代码

     return ($w) w.getFilterRuleToRedis() 

出现了问题。这是因为这样的方法,dubbo 暴露服务的时候把它当成获取属性方法来编译,然后出现类型转化报错

你可能感兴趣的:(java)