Home | 簡體中文 | 繁體中文 | 雜文 | 打賞(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎專欄 | Search | About

5.31. Spring boot with Phoenix

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

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

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