<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-hadoop</artifactId> <version>2.4.0.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.phoenix/phoenix-queryserver-client --> <dependency> <groupId>org.apache.phoenix</groupId> <artifactId>phoenix-queryserver-client</artifactId> <version>4.12.0-HBase-1.3</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.0</version> </dependency> </dependencies>
phoenix 数据源配置项
phoenix: enable: true url: jdbc:phoenix:172.16.0.20 type: com.alibaba.druid.pool.DruidDataSource driver-class-name: org.apache.phoenix.jdbc.PhoenixDriver username: //phoenix的用户名默认为空 password: //phoenix的密码默认为空 default-auto-commit: true
package cn.netkiller.api.config; @Configuration public class PhoenixDataSource { @Autowired private Environment env; @Bean(name = "phoenixJdbcDataSource") @Qualifier("phoenixJdbcDataSource") public DataSource dataSource() { DruidDataSource dataSource = new DruidDataSource(); dataSource.setUrl(env.getProperty("phoenix.url")); dataSource.setDriverClassName(env.getProperty("phoenix.driver-class-name")); dataSource.setUsername(env.getProperty("phoenix.username")); dataSource.setPassword(env.getProperty("phoenix.password")); dataSource.setDefaultAutoCommit(Boolean.valueOf(env.getProperty("phoenix.default-auto-commit"))); return dataSource; } @Bean(name = "phoenixJdbcTemplate") public JdbcTemplate phoenixJdbcTemplate(@Qualifier("phoenixJdbcDataSource") DataSource dataSource) { return new JdbcTemplate(dataSource); } }
原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。