首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >用于Apache Phoenix的Spring DataSource

用于Apache Phoenix的Spring DataSource
EN

Stack Overflow用户
提问于 2018-08-18 20:43:04
回答 1查看 2K关注 0票数 0

我正在使用Spring boot v2.0.4.RELEASE,我正在尝试用apache phoenix配置jdbc数据源。我正在运行一个docker镜像。

c6d57621396b        user/phoenix_hbase:4.10.0   "/bin/sh -c /opt/hba…"   About an hour ago   Up About an hour    0.0.0.0:2181->2181/tcp, 0.0.0.0:60000->60000/tcp, 0.0.0.0:60010->60010/tcp, 0.0.0.0:60020->60020/tcp, 0.0.0.0:60030->60030/tcp   docker-hbase

在运行应用程序时,我不断得到UnsatisfiedDependencyException

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'inMemoryDatabaseShutdownExecutor' defined in class path resource [org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.class]: Unsatisfied dependency expressed through method 'inMemoryDatabaseShutdownExecutor' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource

问题是HikariDataSource不能绑定application.properties中的属性(我的假设)。

spring.datasource.driverClassName=org.apache.phoenix.jdbc.PhoenixDriver
spring.datasource.username=
spring.datasource.password=
spring.datasource.url=jdbc:phoenix:localhost

我也尝试了jdbc:phoenix:docker-hbase,但没有任何变化。

依赖关系:

compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.boot:spring-boot-starter-security')
compile(group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: 'latest.integration')
compile('org.hibernate:hibernate-core:latest.integration')
compile('org.hibernate:hibernate-entitymanager:latest.integration')
compile "org.springframework.data:spring-data-hadoop:2.5.0.RELEASE"
compile(group: 'org.apache.phoenix', name: 'phoenix-core', version:'4.10.0-HBase-1.1') {
        exclude(module: 'slf4j-log4j12')
        exclude(module: 'log4j')
        exclude(module: 'servlet-api')
        exclude(module: 'servlet-api-2.5')
        exclude(module: '*')
    }

只有当我尝试使用apache phoenix进行配置时,它才会失败。我还尝试了Postgres和mysql的配置,一切都像预期的那样工作。

如何配置apache phoenix ?这是可能的吗?

EN

回答 1

Stack Overflow用户

发布于 2018-08-24 17:17:38

我使用Phoenix作为我的数据源的conf:

application.yml

# (DataSourceAutoConfiguration & DataSourceProperties)
spring:
    datasource:
        name: phoenix-hadoop
        url: jdbc:phoenix:${zk-nodes}:${port}:/hbase:${principal}@${realm}:${keytab-path}
        driver-class-name: org.apache.phoenix.jdbc.PhoenixDriver
        type: com.toto.PhoenixNoPoolingDatasource

由于建议不要将连接池与Phoenix驱动程序一起使用,因此我创建了这个类PhoenixNoPoolingDatasource作为我的数据源类型:

import java.sql.Driver;
import java.util.Properties;

public class PhoenixNoPoolingDatasource extends SimpleDriverDataSource {
    public PhoenixNoPoolingDatasource() {
    }

    public PhoenixNoPoolingDatasource(Driver driver, String url) {
        super(driver, url);
    }

    public PhoenixNoPoolingDatasource(Driver driver, String url, String username, String password) {
        super(driver, url, username, password);
    }

    public PhoenixNoPoolingDatasource(Driver driver, String url, Properties conProps) {
        super(driver, url, conProps);
    }

    public void setDriverClassName(String driverClassName) {
        try {
            Class<?> driverClass = this.getClass().getClassLoader().loadClass(driverClassName);
            setDriverClass((Class<? extends Driver>) driverClass);
        } catch (Exception e) {
            throw new RuntimeException("Failed to load class of driverClassName " + driverClassName, e);
        }
    }
}

此外,您可能希望查看此方言https://github.com/jruesga/phoenix-hibernate-dialect,因为Phoenix方言不是ANSI SQL。主要区别在于不存在update和insert语句。相反,Phoenix使用upsert语句。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51908794

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档