知乎專欄 | 多維度架構 | | | 微信號 netkiller-ebook | | | QQ群:128659835 請註明“讀者” |
<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); } }