spring boot整合hbase,解决依赖冲突问题

springboot要整合hbase链接api:phenix,结果运行时报以下错误:

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call the method com.google.common.collect.Multimaps.asMap(Lcom/google/common/collect/ListMultimap;)Ljava/util/Map; but it does not exist. Its class, com.google.common.collect.Multimaps, is available from the following locations:

    jar:file:/C:/Users/Person/.m2/repository/com/google/guava/guava/14.0/guava-14.0.jar!/com/google/common/collect/Multimaps.class

It was loaded from the following location:

    file:/C:/Users/Person/.m2/repository/com/google/guava/guava/14.0/guava-14.0.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of com.google.common.collect.Multimaps

在网上查了查报错的原因是:
在这里插入图片描述
原因是在项目中用到了swagger2,接口测试
他的依赖中:
谷歌的guava包版本为:20

 <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>20.0</version>
      <scope>compile</scope>
    </dependency>

而hbase中guava版本为13

<guava.version>13.0.1</guava.version>

现在想到的解决办法是:

maven-shade-plugin
这个办法
关于它:
大家可以通过以下链接了解:
链接一
链接二

但是在翻maven仓库时,
swagger2的2.10.0版本,并不依赖guava了
在这里插入图片描述
传送门
而在2.9版本还是依赖的:
在这里插入图片描述
传送门2

所以问题解决就简单:升级版本就行了!


我还尝试用maven的exclusion解决,
在这里插入图片描述
结果报以下错误:

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call the method com.google.common.collect.Multimaps.asMap(Lcom/google/common/collect/ListMultimap;)Ljava/util/Map; but it does not exist. Its class, com.google.common.collect.Multimaps, is available from the following locations:

    jar:file:/C:/Users/Person/.m2/repository/com/google/guava/guava/14.0/guava-14.0.jar!/com/google/common/collect/Multimaps.class

It was loaded from the following location:

    file:/C:/Users/Person/.m2/repository/com/google/guava/guava/14.0/guava-14.0.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of com.google.common.collect.Multimaps

据说包重复造成的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Spring Cloud中访问HBase,你可以使用HBaseJava API或者Spring Data Hadoop。下面我将介绍两种方法。 1. 使用HBaseJava API: 首先,你需要在你的项目中添加HBase依赖。在Maven项目中,你可以在pom.xml文件中添加以下依赖: ```xml <dependency> <groupId>org.apache.hbase</groupId> <artifactId>hbase-client</artifactId> <version>VERSION_NUMBER</version> </dependency> ``` 然后,你可以使用HBaseJava API编写代码来访问HBase。你可以创建HBase的连接,并使用Table接口来执行操作。以下是一个简单的示例: ```java // 创建HBase连接 Configuration config = HBaseConfiguration.create(); Connection connection = ConnectionFactory.createConnection(config); // 获取表对象 Table table = connection.getTable(TableName.valueOf("your_table_name")); // 执行操作,例如获取某一行数据 Get get = new Get(Bytes.toBytes("your_row_key")); Result result = table.get(get); // 处理结果 byte[] value = result.getValue(Bytes.toBytes("your_column_family"), Bytes.toBytes("your_column_qualifier")); System.out.println(Bytes.toString(value)); // 关闭连接 table.close(); connection.close(); ``` 2. 使用Spring Data Hadoop: Spring Data Hadoop是Spring框架的一个模块,它提供了与Hadoop生态系统集成的功能。你可以使用Spring Data Hadoop来访问HBase。 首先,你需要在你的项目中添加Spring Data Hadoop的依赖。在Maven项目中,你可以在pom.xml文件中添加以下依赖: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-hadoop</artifactId> <version>VERSION_NUMBER</version> </dependency> ``` 接下来,你可以使用Spring Data Hadoop的HbaseTemplate来执行HBase操作。以下是一个简单的示例: ```java @Autowired private HbaseTemplate hbaseTemplate; public void getDataFromHBase() { String tableName = "your_table_name"; String rowKey = "your_row_key"; String columnFamily = "your_column_family"; String columnQualifier = "your_column_qualifier"; byte[] value = hbaseTemplate.get(tableName, rowKey, columnFamily, columnQualifier); System.out.println(Bytes.toString(value)); } ``` 无论你选择使用HBaseJava API还是Spring Data Hadoop,都需要确保你的应用程序能够访问HBase集群,并且具有正确的权限配置。另外,还需要根据你的具体需求进行适当的调整和优化。希望这些信息对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值