无法在Spring中加载JDBC驱动程序类[org.apache.hive.jdbc.HiveDriver]

时间:2017-06-13 07:54:21

标签: java mysql spring jdbc

我尝试通过我的spring应用程序连接hive。我已经使用MYSQL server配置了hive。我使用了以下属性进行数据库配置。

db.dialect=org.hibernate.dialect.MySQLDialect
db.driver=org.apache.hive.jdbc.HiveDriver
db.url=jdbc:hive2://localhost:10000/MY_DATABASE
db.class=org.apache.hive.jdbc.HiveDriver
db.user=hadoop
db.password=hadoop

这是我在db.properties文件中使用的。但是在运行应用程序时我得到了以下异常。

PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [org.apache.hive.jdbc.HiveDriver]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:353)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:153)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)

在pom.xml中我添加了以下依赖

            <dependency>
              <groupId>org.apache.hive</groupId>
              <artifactId>hive-jdbc</artifactId>
              <version>2.1.1</version>
            </dependency>

1 个答案:

答案 0 :(得分:0)

您使用了错误的驱动程序类名称,因此使用了错误。你需要替换这个

db.driver=org.apache.hive.jdbc.HiveDriver

db.driver=org.apache.hadoop.hive.jdbc.HiveDriver

您可以参考驱动程序文档here,以防您需要。

希望这可以解决你的问题!