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

替换es7的plugin或者是本地调试canal-adapter的时候出现com.alibaba.druid.pool.DruidDataSource cannot be cast to com.alibaba.druid.pool.DruidDataSource #3144

Closed
2 tasks done
liuxuzxx opened this issue Nov 3, 2020 · 18 comments
Labels
Milestone

Comments

@liuxuzxx
Copy link

liuxuzxx commented Nov 3, 2020

  • I have searched the issues of this repository and believe that this is not a duplicate.
  • I have checked the FAQ of this repository and believe that this is not a duplicate.

environment

  • canal version 1.1.5-SNAPSHOT
  • mysql version 8.0.22

Issue Description

本地拉取master分支代码进行调试client-adapter的时候。或者是手动打包es7的plugin放到1.1.5-SNAPSHOT的canal-adapter的plugin下面,替换之前的es7x的插件包的时候。都会出现如下日志:

2020-11-03 19:22:17.384 [main] ERROR c.a.o.canal.adapter.launcher.loader.CanalAdapterLoader - Load canal adapter: es7 failed
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.ClassCastException: com.alibaba.druid.pool.DruidDataSource cannot be cast to com.alibaba.druid.pool.DruidDataSource
	at com.alibaba.otter.canal.client.adapter.es7x.ES7xAdapter.init(ES7xAdapter.java:54) ~[client-adapter.es7x-1.1.5-SNAPSHOT-jar-with-dependencies.jar:na]
	at com.alibaba.otter.canal.adapter.launcher.loader.CanalAdapterLoader.loadAdapter(CanalAdapterLoader.java:225) [classes/:na]
	at com.alibaba.otter.canal.adapter.launcher.loader.CanalAdapterLoader.init(CanalAdapterLoader.java:56) [classes/:na]
	at com.alibaba.otter.canal.adapter.launcher.loader.CanalAdapterService.init(CanalAdapterService.java:60) [classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_231]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_231]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_231]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_231]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:365) [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:308) [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:135) [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:422) [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1694) [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:579) [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501) [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$1(AbstractBeanFactory.java:353) [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.cloud.context.scope.GenericScope$BeanLifecycleWrapper.getBean(GenericScope.java:390) ~[spring-cloud-context-2.0.0.RELEASE.jar:2.0.0.RELEASE]
	at org.springframework.cloud.context.scope.GenericScope.get(GenericScope.java:184) ~[spring-cloud-context-2.0.0.RELEASE.jar:2.0.0.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:350) [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1089) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.cloud.context.scope.refresh.RefreshScope.eagerlyInitialize(RefreshScope.java:126) ~[spring-cloud-context-2.0.0.RELEASE.jar:2.0.0.RELEASE]
	at org.springframework.cloud.context.scope.refresh.RefreshScope.start(RefreshScope.java:117) ~[spring-cloud-context-2.0.0.RELEASE.jar:2.0.0.RELEASE]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_231]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_231]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_231]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_231]
	at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:264) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:182) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:144) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:400) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:354) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:888) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:161) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
	at com.alibaba.otter.canal.adapter.launcher.CanalAdapterApplication.main(CanalAdapterApplication.java:19) ~[classes/:na]
Caused by: java.lang.RuntimeException: java.lang.ClassCastException: com.alibaba.druid.pool.DruidDataSource cannot be cast to com.alibaba.druid.pool.DruidDataSource
	at com.alibaba.otter.canal.client.adapter.es.core.ESAdapter.init(ESAdapter.java:83) ~[client-adapter.es7x-1.1.5-SNAPSHOT-jar-with-dependencies.jar:na]
	at com.alibaba.otter.canal.client.adapter.es7x.ES7xAdapter.init(ES7xAdapter.java:52) ~[client-adapter.es7x-1.1.5-SNAPSHOT-jar-with-dependencies.jar:na]
	... 42 common frames omitted
Caused by: java.lang.ClassCastException: com.alibaba.druid.pool.DruidDataSource cannot be cast to com.alibaba.druid.pool.DruidDataSource
	at com.alibaba.otter.canal.client.adapter.es.core.ESAdapter.addSyncConfigToCache(ESAdapter.java:146) ~[client-adapter.es7x-1.1.5-SNAPSHOT-jar-with-dependencies.jar:na]
	at com.alibaba.otter.canal.client.adapter.es.core.ESAdapter.init(ESAdapter.java:75) ~[client-adapter.es7x-1.1.5-SNAPSHOT-jar-with-dependencies.jar:na]
	... 43 common frames omitted

Steps to reproduce

本地调试:

1.mvn clean package -Dmaven.test.skip=true
2.启动CanalAdapterApplication

Expected behaviour

启动正常

Actual behaviour

在加载Conf文件夹之后的文件获取DataSource的时候,出现上面的异常信息!

If there is an exception, please attach the exception trace:

Just put your stack trace here!
@liuxuzxx
Copy link
Author

liuxuzxx commented Nov 3, 2020

跟踪了一下代码,发现这个问题的原因是:

com.alibaba.otter.canal.client.adapter.es.core.ESAdapter类的
146行:
DruidDataSource dataSource = DatasourceConfig.DATA_SOURCES.get(config.getDataSourceKey());

DruidDataSource.class.getClassLoader()是:
com.alibaba.otter.canal.client.adapter.support.URLClassExtensionLoader



DatasourceConfig.DATA_SOURCES.get(config.getDataSourceKey()).getClass().getClassLoader()是:
sun.misc.Launcher.AppClassLoader

这么看上面的异常日志信息,确实也就正常了

@liuxuzxx
Copy link
Author

liuxuzxx commented Nov 3, 2020

解决了,解决方案如下:

client-adapter.escore的pom.xml的关于druid的配置,需要设置scope为provider
之前的配置是:
<dependency>
     <groupId>com.alibaba</groupId>
     <artifactId>druid</artifactId>
</dependency>

修改之后的配置为:
<dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid</artifactId>
        <scope>provided</scope>//加上这行配置,让es的xxxx-with-dependency.jar不包含druid相关包
</dependency>

主要是client-adapter.es7x-1.1.5-SNAPSHOT-jar-with-dependencies.jar包含druid的包,导致加载的时候AppClassLoader类加载器
加载了一遍druid,然后自定义的URLClassExtensionLoader又从client-adapter.es7x-1.1.5-SNAPSHOT-jar-with-dependencies.jar
这个包里面加载了一遍druid,导致,他俩的DruidDataSource的类加载器不一样,导致无法cast

@Reyoo
Copy link

Reyoo commented Jun 9, 2021

找到问题然后怎么办 重新打包吗 。重新打得包是escore 吗 还是client-adapter.es7x-1.1.5-SNAPSHOT-jar-with-dependencies.jar

1 similar comment
@Reyoo
Copy link

Reyoo commented Jun 9, 2021

找到问题然后怎么办 重新打包吗 。重新打得包是escore 吗 还是client-adapter.es7x-1.1.5-SNAPSHOT-jar-with-dependencies.jar

@junshixiansheng
Copy link

找到问题然后怎么办 重新打包吗 。重新打得包是escore 吗 还是client-adapter.es7x-1.1.5-SNAPSHOT-jar-with-dependencies.jar

重新打包client-adapter 获取插件,替换就可以

@liuxuzxx
Copy link
Author

找到问题然后怎么办 重新打包吗 。重新打得包是escore 吗 还是client-adapter.es7x-1.1.5-SNAPSHOT-jar-with-dependencies.jar

实在是抱歉,时间太久远了,我模糊记得是重新打包之后的操作!应该和 @junshixiansheng 采取的方式一样!实在是抱歉啊,当时整完之后,看作者好像也不怎么回应canal的issule,所以就忘记记录处理方案了!

@RYXB
Copy link

RYXB commented Jun 13, 2021

找到问题然后怎么办 重新打包吗 。重新打得包是escore 吗 还是client-adapter.es7x-1.1.5-SNAPSHOT-jar-with-dependencies.jar

您是怎么操做的?配置好依赖后,重新单独打包es7的模块,然后再放到adapter的plugs下吗

@mailbyms
Copy link

找到问题然后怎么办 重新打包吗 。重新打得包是escore 吗 还是client-adapter.es7x-1.1.5-SNAPSHOT-jar-with-dependencies.jar

您是怎么操做的?配置好依赖后,重新单独打包es7的模块,然后再放到adapter的plugs下吗

用新编译出来的 client-adapter.es7x-1.1.5-jar-with-dependencies.jar ,替换原来 plugin 目录下的即可

at1559 pushed a commit to at1559/canal that referenced this issue Aug 8, 2021
at1559 pushed a commit to at1559/canal that referenced this issue Aug 8, 2021
at1559 added a commit to at1559/canal that referenced this issue Aug 8, 2021
@agapple agapple closed this as completed Oct 9, 2021
@agapple agapple added this to the v1.1.6 milestone Oct 9, 2021
@agapple agapple added the bug label Oct 9, 2021
@NonSecurity
Copy link

替换文件方式可以了

@junshixiansheng
Copy link

junshixiansheng commented Jan 17, 2022 via email

@acger
Copy link

acger commented Feb 24, 2022

是的,将alpha-2版本的插件替换过去就没有问题了,还有就是application.yml下的outerAdapters配置不需要加http协议头。Have a good day(^_^).

@junshixiansheng
Copy link

junshixiansheng commented Feb 24, 2022 via email

agapple pushed a commit that referenced this issue May 13, 2022
@xiaofei159
Copy link

我在escor的druid加入provide后报错java.lang.NoSuchMethodError: 'java.lang.String com.alibaba.druid.sql.ast.statement.SQLExprTableSource.getTableName(),请问怎么解决

@junshixiansheng
Copy link

junshixiansheng commented Feb 27, 2023 via email

@yl3143051
Copy link

我在escor的druid加入provide后报错java.lang.NoSuchMethodError: 'java.lang.String com.alibaba.druid.sql.ast.statement.SQLExprTableSource.getTableName(),请问怎么解决

大佬,有解决嘛,这两天也遇到这个问题了

@junshixiansheng
Copy link

junshixiansheng commented Aug 13, 2023 via email

@GuoJunWenC
Copy link

怎么解决的,cannal项目打包就报错

@junshixiansheng
Copy link

junshixiansheng commented Sep 5, 2023 via email

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

No branches or pull requests