尝试从eclipse spring xml文件连接到配置单元时出现套接字连接错误

s71maibg  于 2021-06-03  发布在  Hadoop
关注(0)|答案(1)|浏览(309)

org.springframework.beans.factory.beancreationexception:创建名为“hiveserver”的bean时出错:调用init方法失败;嵌套异常为org.apache.thrift.transport.ttTransportException:无法在地址0.0.0.0/0.0.0:10000上创建serversocket。

rqenqsqc

rqenqsqc1#

可能是配置文件中不正确的bean声明。
您可以按照以下步骤操作:
创建hive-config.xml

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:c="http://www.springframework.org/schema/c"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<context:property-placeholder location="hive.properties"/> 
<bean id="hive-driver" class="org.apache.hadoop.hive.jdbc.HiveDriver"/>
<bean id="hive-ds" class="org.springframework.jdbc.datasource.SimpleDriverDataSource"
 c:driver-ref="hive-driver" c:url="${hive.url}"/>
</beans>

创建hive.properties

hive.url=jdbc:hive://localhost:10000/default

添加spring jdbc jar
获取java代码中的连接。

ApplicationContext ac = new FileSystemXmlApplicationContext("hive-config.xml");
DataSource dataSource =  (DataSource) ac.getBean("hive-ds");
Connection con =dataSource.getConnection();

并开始向hiveserver启动查询

相关问题