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

[1.1.0]canal与springboot.2.0.4集成异常,guava-18 版本太低,springboot 集成guava-20 #912

Closed
panjianping opened this issue Sep 4, 2018 · 12 comments

Comments

@panjianping
Copy link

java.lang.NoSuchMethodError: com.google.common.collect.MapMaker.makeComputingMap(Lcom/google/common/base/Function;)Ljava/util/concurrent/ConcurrentMap; at com.google.common.collect.MigrateMap.makeComputingMap(MigrateMap.java:17) ~[canal.common-1.1.0.jar:na] at com.alibaba.otter.canal.common.zookeeper.ZkClientx.<clinit>(ZkClientx.java:26) ~[canal.common-1.1.0.jar:na] at com.alibaba.otter.canal.client.kafka.KafkaCanalConnector.<init>(KafkaCanalConnector.java:52) ~[classes/:na] at com.alibaba.otter.canal.client.kafka.KafkaCanalConnectors.newKafkaConnector(KafkaCanalConnectors.java:47) ~[classes/:na] at com.louxun.search.service.SyncDataToESJob.syncHouseDataToES(SyncDataToESJob.java:41) ~[classes/:na] at com.louxun.search.listener.StartupListener.onApplicationEvent(StartupListener.java:18) ~[classes/:na] at com.louxun.search.listener.StartupListener.onApplicationEvent(StartupListener.java:10) ~[classes/:na] at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE] at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:400) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE] at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:354) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:888) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:161) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:330) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE] at com.louxun.search.SearchApplication.main(SearchApplication.java:10) [classes/:na]

@gezhiwei8899
Copy link

貌似可以解决把?

@panjianping
Copy link
Author

我是修改了原代码解决的
`
package com.alibaba.otter.canal.common.zookeeper;

import java.util.Map;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import org.I0Itec.zkclient.IZkConnection;
import org.I0Itec.zkclient.ZkClient;
import org.I0Itec.zkclient.exception.ZkException;
import org.I0Itec.zkclient.exception.ZkInterruptedException;
import org.I0Itec.zkclient.exception.ZkNoNodeException;
import org.I0Itec.zkclient.exception.ZkNodeExistsException;
import org.I0Itec.zkclient.serialize.ZkSerializer;
import org.apache.zookeeper.CreateMode;

import com.google.common.base.Function;
import com.google.common.collect.MigrateMap;

/**

  • 使用自定义的ZooKeeperx for zk connection

  • @author jianghang 2012-7-10 下午02:31:15

  • @Version 1.0.0
    */
    public class ZkClientx extends ZkClient {

    /* BUG 对于zkclient进行一次缓存,避免一个jvm内部使用多个zk connection
    private static Map<String, ZkClientx> clients = MigrateMap.makeComputingMap(new Function<String, ZkClientx>() {
    public ZkClientx apply(String servers) {
    return new ZkClientx(servers);
    }
    });
    */

    //使用 guava 新的方式 替代以前旧的(旧的与springboot2.0集成有问题)
    private static LoadingCache<String, ZkClientx> clients = CacheBuilder.newBuilder().build(
    new CacheLoader<String, ZkClientx>() {
    public ZkClientx load(String servers) {
    return new ZkClientx(servers);
    }
    });

    // 其他原代码省略,未做修改
    }
    `

@gezhiwei8899
Copy link

我说的是你在pom里面 都使用到guava的地方 其中一个旧依赖的地方加上exclusion标签,看看能不能解决

@panjianping
Copy link
Author

不行啊,canal依赖的是旧版本guava-18的,用上新guava-20的话其中一个类里过时的方法已经被移除了,想统一用新版本行不通啊,所以我现在修改了canal里面源码,将过期的guava方法替换成新的方式

@kervin521
Copy link

canal使用spring版本为3.2.6,而spring-boot2.0.4依赖spring版本为5.x
在版本上差异比较大,谨慎使用

@agapple
Copy link
Member

agapple commented Sep 6, 2018

有替换成功的,可以提交一个PR给我

@gezhiwei8899
Copy link

@panjianping 兄弟你后来用的是哪个版本的canal 和哪个版本的springboot

@panjianping
Copy link
Author

@gezhiwei8899 就用了canal-1.1.0 和 springboot-2.0.4 的,修改了canal 的源码 ZkClientx.java

@gezhiwei8899
Copy link

我还引入了dubbo根本起不来了 @panjianping

@gezhiwei8899
Copy link

@panjianping 能不能重新canal的一个方法 避免修改源码嘛

@panjianping
Copy link
Author

@gezhiwei8899 现在主要是问题是,高版本的spring-boot使用的是guava-20,而当前canal中的ZkClientx.java依赖提guava-18中的方法,但这个方法在guava-20中已经被移除了,所以不想修改原码的话,需要使用spring-3.x的版本。我大概想到的解决方法就这个了

@yin007008
Copy link

yin007008 commented Sep 11, 2018

直接在你的pom里面显示依赖guava-18不就可以了么? 我就是这么解决的

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>18.0</version>
    </dependency>

agapple added a commit that referenced this issue Sep 11, 2018
fix #912 解决guava冲突问题
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants