Home | 簡體中文 | 繁體中文 | 雜文 | 知乎專欄 | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 視頻教程 | 打賞(Donations) | About
知乎專欄多維度架構 | 微信號 netkiller-ebook | QQ群:128659835 請註明“讀者”

2.30. Spring boot with Phoenix

2.30.1. Maven

			
<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>  
			
		

2.30.2. application.properties

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  
			
		

2.30.3. Configuration

			
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);  
     }  
}