Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jarslink demo 整合sofarpc 出现问题 #94

Open
jiang2015 opened this issue Aug 9, 2018 · 6 comments
Open

jarslink demo 整合sofarpc 出现问题 #94

jiang2015 opened this issue Aug 9, 2018 · 6 comments
Labels
question Further information is requested

Comments

@jiang2015
Copy link

jiang2015 commented Aug 9, 2018

Your question

利用jarslink中的biz-jvm-invocation-sample 引用sofa-rpc,出现问题,具体改造点:
1.原来的注解方式改为xml配置方式,引入service-provide.xml,service-consumer.xml,
如果传输协议采用sofa:binding.jvm/的话,执行没有问题。
如果传输协议采用sofa:binding.bolt/的话,就会报异常。

demo地址:
https://github.com/jiang2015/biz-jvm-invocation-sample/tree/master

按照以下步骤执行 sample:

  1. cd biz-jvm-invocation-sample/facade && mvn clean install 在 facade 应用根目录中执行 mvn clean install 命令,把 facade 包安装到本地 maven 仓库,以便在 app-one 和 app-two 中添加 facade 依赖:

  2. cd biz-jvm-invocation-sample/app-one && mvn clean package 在 app-one 应用根目录中执行 mvn clean package 命令,将应用打包成 Ark 包和 Biz 包,文件将输出到 biz-jvm-invocation-sample/app-one/target 目录

  3. cd biz-jvm-invocation-sample/app-two && mvn clean package 在 app-two 应用根目录中执行 mvn clean package 命令,将应用打包成 Ark 包和 Biz 包,文件将输出到 biz-jvm-invocation-sample/app-two/target 目录

  4. 使用 java -jar 启动 app-one 应用的 Ark 包

  5. 使用 telnet localhost 1234 进入 Jarslink2.0 指令交互界面,并执行 install -b 指令,安装启动 app-two 的 Biz 包。

  6. 执行install -b 命令的场合,例如:install -b file:\\D:\work\src\gitsrc\sofa-jarslink\sofa-jarslink-samples\biz-jvm-invocation-sample\app-two\target\app-two-1.0.0-ark-biz.jar
    会抛出异常:

2018-08-09 11:41:35.336 ERROR 9096 --- [nk-command-0-T1] o.s.boot.SpringApplication : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.alipay.sofa.runtime.spring.factory.ServiceFactoryBean#0': Invocation of init method failed; nested exception is java.lang.LinkageError: loader constraint violation: when resolving method "com.alipay.sofa.runt
ime.spi.service.BindingConverterContext.setApplicationContext(Lorg/springframework/context/ApplicationContext;)V" the class loader (instance of com/alipay/sofa/ark/container/service/classloader/BizClassLoader) of the current class, com/alipay/sofa/runtime/spring/factory/AbstractContractFactoryBean,
and the class loader (instance of com/alipay/sofa/ark/container/service/classloader/PluginClassLoader) for the method's defining class, com/alipay/sofa/runtime/spi/service/BindingConverterContext, have different Class objects for the type org/springframework/context/ApplicationContext used in the si
gnature
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583) ~[spring-beans-4.3.4.RELEASE.jar!/:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.4.RELEASE.jar!/:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.4.RELEASE.jar!/:na]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.4.RELEASE.jar!/:na]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.4.RELEASE.jar!/:na]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.4.RELEASE.jar!/:na]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.4.RELEASE.jar!/:na]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:735) ~[spring-beans-4.3.4.RELEASE.jar!/:na]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.4.RELEASE.jar!/:na]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.4.RELEASE.jar!/:na]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) ~[spring-boot-1.4.2.RELEASE.jar!/:na]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) ~[spring-boot-1.4.2.RELEASE.jar!/:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-1.4.2.RELEASE.jar!/:na]
at me.qlong.tech.service.AppTwoApplication.main(AppTwoApplication.java:33) [app-two-1.0.0-ark-biz.jar!/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_91]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_91]
at com.alipay.sofa.ark.bootstrap.MainMethodRunner.run(MainMethodRunner.java:48) [sofa-ark-archive-0.4.0.jar!/:na]
at com.alipay.sofa.ark.container.model.BizModel.start(BizModel.java:179) [sofa-ark-container-0.4.0.jar!/:na]
at com.alipay.sofa.jarslink.runtime.command.InstallCommand$1.run(InstallCommand.java:78) [sofa-jarslink-runtime-2.0.0-SNAPSHOT.jar!/:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_91]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_91]
at java.lang.Thread.run(Unknown Source) [na:1.8.0_91]
Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "com.alipay.sofa.runtime.spi.service.BindingConverterContext.setApplicationContext(Lorg/springframework/context/ApplicationContext;)V" the class loader (instance of com/alipay/sofa/ark/container/service/classloader
/BizClassLoader) of the current class, com/alipay/sofa/runtime/spring/factory/AbstractContractFactoryBean, and the class loader (instance of com/alipay/sofa/ark/container/service/classloader/PluginClassLoader) for the method's defining class, com/alipay/sofa/runtime/spi/service/BindingConverterConte
xt, have different Class objects for the type org/springframework/context/ApplicationContext used in the signature
at com.alipay.sofa.runtime.spring.factory.AbstractContractFactoryBean.parseBindings(AbstractContractFactoryBean.java:120) ~[runtime-sofa-boot-starter-2.5.0-SNAPSHOT.jar!/:na]
at com.alipay.sofa.runtime.spring.factory.AbstractContractFactoryBean.afterPropertiesSet(AbstractContractFactoryBean.java:95) ~[runtime-sofa-boot-starter-2.5.0-SNAPSHOT.jar!/:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642) ~[spring-beans-4.3.4.RELEASE.jar!/:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579) ~[spring-beans-4.3.4.RELEASE.jar!/:na]

@QilongZhang QilongZhang added the question Further information is requested label Aug 9, 2018
@QilongZhang
Copy link
Contributor

@jiang2015 app-one main 没有main方法, 补充下?

@JoeKerouac
Copy link
Contributor

@jiang2015 @QilongZhang 看了下源码,这个问题只有在使用非jvm的binding是才会有,因为在同一个JVM中使用非jvm的binding,导致BindingConverterContext类出现问题(jvm binding不使用这个),大概逻辑是:

  • 启动app-one,app-one启动时需要用到BindingConverterContext类,该类是sofa-rpc插件导出的类,但是里边的ApplicationContext不是,所以ApplicationContext会使用BizClassloader从app-one的本地加载;
  • 使用命令启动app-two,app-two同样需要用到BindingConverterContext类,使用sofa-rpc插件导出的class实例,该类不会冲突,但是ApplicationContext不是sofa-rpc导出的类,所以会使用BizClassloader从app-two的本地加载,这时因为app-one已经加载过BindingConverterContext,BindingConverterContext中的ApplicationContext已经绑定了app-one加载的ApplicationContext,而此时app-two又要尝试使用自己加载的ApplicationContext的class实例绑定BindingConverterContext,所以报了LinkageError;

解决方案:
1.不在同一个JVM中使用非jvm binding;
2.将spring相关的class也从sofa-rpc-boot-projects项目导出,这样ApplicationContext的class实例就会统一;

@jiang2015
Copy link
Author

@QilongZhang 不好意思,刚上传上去。

@jiang2015
Copy link
Author

@JoeKerouac 首先谢谢大神的指点和说明,我觉得一个jvm当中使用非jvm binding 感觉有点。。。

@JoeKerouac
Copy link
Contributor

@jiang2015 有什么问题吗?

@jiang2015
Copy link
Author

@JoeKerouac 没有问题,我觉得使用方式上:
1.不在同一个JVM中使用非jvm binding;
2.同一个JVM中使用jvm bindings;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants