복붙노트

[SPRING] XML 대신 Java를 사용하여 Spring Boot에서 hbase를 사용하는 방법은 무엇입니까?

SPRING

XML 대신 Java를 사용하여 Spring Boot에서 hbase를 사용하는 방법은 무엇입니까?

나는 Spring Boot Hadoop을 가지고 있고 Spring HbaseTemplate을 이용하고 싶다. 내 문제는 구성 및 설정의 "xml"방법에 대한 정보 만있는 설명서입니다.

공식 문서의 xml과 반대로 Java에서 hbase 구성에 대한 구성을 어떻게 그리고 어디에서 정의 할 수 있습니까?

http://docs.spring.io/spring-hadoop/docs/1.0.1.RC1/reference/html/hbase.html

해결법

  1. ==============================

    1.글쎄 그것은 실제로 예상되는 대답은 아니지만 너무 많은 의견을 내기 위해 개발하고 싶습니다.

    글쎄 그것은 실제로 예상되는 대답은 아니지만 너무 많은 의견을 내기 위해 개발하고 싶습니다.

    Apache Hadoop 용 Spring - 마지막으로 발표 된 버전의 Reference Documentation을주의 깊게 읽고 네임 스페이스 구성에 대한 예제와 세부 정보가 포함되어 있으면 Java 구성에서 단일 행을 찾을 수 없습니다.

    필자가 알고있는 점은 현재 Apache Hadoop 용 Spring에서만 네임 스페이스 구성 만 지원된다는 것입니다. 네임 스페이스를 지원하는 클래스를 살펴보고 java config를 사용하여 동일한 결과를 얻는 방법을 찾기 위해 작업 구성을 해킹하는 것이 가능해야하지만 정직하게는 비용 / 이득 비율로 인해이를 정당화 할 수 없다고 생각합니다. 현재 문서화되지 않았으므로, 나중에 깨뜨릴 것을 잊지 않았는지 결코 확신 할 수 없습니다.

    Spring이 Java config Spring 애플리케이션에 xml 설정 파일을 포함하도록 제안 했으므로 현재 Java 설정을 모두 유지하고 제공된 네임 스페이스를 사용하여 xml에 Apache Hadoop 파트를 작성하고 구성에 @ImportResource 주석을 추가하기 만하면된다. 수업. Spring의 hadoop 설정이 classpath의 루트에 hadoopContext.xml이라면 다음과 같이 작성할 수있다.

    @Configuration
    ...
    @ImportResource("classpath:/hadoopContext.xml")
    public classConfig {
    ...
    }
    

    또는 Spring에서 스캔 할 수 있도록 관리하는 xml 구성에 @Configuration 래퍼를 사용할 수 있습니다.

    @Configuration
    @ImportResource("classpath:/hadoopContext.xml")
    public class HadoopConfig {
    
    }
    
  2. ==============================

    2.HBase 용 Java 기반 구성이 아직 정식으로 제공되지는 않지만 (최근 Spring Hadoop 2.2.1과 같이) 깨끗한 해결 방법이 있습니다. 관련 ZooKeeper 세부 사항을 Java 기반 Spring Hadoop 구성의 특성으로 포함하십시오. 그런 다음, hbase 구성 XML 태그에는 구성 세부 사항이 포함될 필요가 없습니다. 규약에 따라, Java 기반 HadoopConfigConfigurer에 의해 정의 된 hadoopConfiguration bean에 의존 할 것이다.

    HBase 용 Java 기반 구성이 아직 정식으로 제공되지는 않지만 (최근 Spring Hadoop 2.2.1과 같이) 깨끗한 해결 방법이 있습니다. 관련 ZooKeeper 세부 사항을 Java 기반 Spring Hadoop 구성의 특성으로 포함하십시오. 그런 다음, hbase 구성 XML 태그에는 구성 세부 사항이 포함될 필요가 없습니다. 규약에 따라, Java 기반 HadoopConfigConfigurer에 의해 정의 된 hadoopConfiguration bean에 의존 할 것이다.

    @Configuration
    @EnableHadoop
    public class MapReduceConfiguration extends SpringHadoopConfigurerAdapter {
        @Override
        public void configure(HadoopConfigConfigurer config) throws Exception {
            config
                    .fileSystemUri(myConfigManager.getHadoopFsUri())
                    .resourceManagerAddress(myConfigManager.getHadoopResourceManagerAddress())
                    .withProperties()
                    .property("hbase.zookeeper.quorum", myConfigManager.getZookeeperQuorum())
                    .property("hbase.zookeeper.property.clientPort", myConfigManager.getZookeeperPort())
                    .property("hbase.client.scanner.caching", "1");
        }
    }
    

    나머지 XML 구성은 전개 환경과 관련이 없습니다.

    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:hdp="http://www.springframework.org/schema/hadoop"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/hadoop http://www.springframework.org/schema/hadoop/spring-hadoop.xsd">
        <hdp:hbase-configuration />
    </beans>
    
  3. ==============================

    3.이 샘플들을 체크 아웃 할 수 있습니다. https://github.com/trisberg/bostonhadoop http://santoshkrsh.blogspot.in/2014/01/spring-restful-service-crud-operation.html https://github.com/spring-projects/spring-hadoop-samples/tree/master/hbase

    이 샘플들을 체크 아웃 할 수 있습니다. https://github.com/trisberg/bostonhadoop http://santoshkrsh.blogspot.in/2014/01/spring-restful-service-crud-operation.html https://github.com/spring-projects/spring-hadoop-samples/tree/master/hbase

  4. ==============================

    4.나는 xml없이 스프링 부팅 응용 프로그램에서 hbase를 사용하기위한 간단한 데모 프로젝트를 작성했습니다.

    나는 xml없이 스프링 부팅 응용 프로그램에서 hbase를 사용하기위한 간단한 데모 프로젝트를 작성했습니다.

    이 데모는 주로 spring-data-hadoop과 hbase-client에 의존합니다. gradle 종속성 :

    compile('org.springframework.boot:spring-boot-starter-data-rest')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile 'org.springframework.data:spring-data-hadoop:2.5.0.RELEASE'
    compile('org.apache.hbase:hbase-client:1.3.1'){
        exclude group :'log4j',module:'log4j'
        exclude group :'org.slf4j',module:'slf4j-log4j12'
        exclude group: 'javax.servlet', module: 'servlet-api'
    }
    compile('org.springframework.boot:spring-boot-configuration-processor')
    providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
    

    Spring 부트의 application.properties (XML 없음!)에서 hbase 연결 매개 변수를 구성하십시오.

    spring.data.hbase.zkQuorum=192.168.0.109:2181
    spring.data.hbase.zkBasePath=/hbase
    spring.data.hbase.rootDir=file:///home/hbase-1.2.2
    

    HbaseProperties.java 클래스 :

    @ConfigurationProperties(prefix = "spring.data.hbase")
    public class HbaseProperties {
        // Addresses of all registered ZK servers.
        private String zkQuorum;
    
        // Location of HBase home directory
        private String rootDir;
    
        // Root node of this cluster in ZK.
        private String zkBasePath;
    
        // getters and setters...
    
    }
    

    HbaseConfig.java, 구성을 HbaseTemplate에 삽입하십시오.

    import org.apache.hadoop.hbase.HBaseConfiguration;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.context.properties.EnableConfigurationProperties;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.data.hadoop.hbase.HbaseTemplate;
    
    @Configuration
    @EnableConfigurationProperties(HbaseProperties.class)
    public class HbaseConfig {
    
        @Autowired
        private HbaseProperties hbaseProperties;
    
        @Bean
        public HbaseTemplate hbaseTemplate() {
            org.apache.hadoop.conf.Configuration configuration = HBaseConfiguration.create();
            configuration.set("hbase.zookeeper.quorum", this.hbaseProperties.getZkQuorum());
            configuration.set("hbase.rootdir", this.hbaseProperties.getRootDir());
            configuration.set("zookeeper.znode.parent", this.hbaseProperties.getZkBasePath());
            return new HbaseTemplate(configuration);
        }
    
    }
    

    서비스 클래스, 우리는 지금 구성된 HbaseTemplate을 사용할 수 있습니다 :

    import javax.annotation.PostConstruct;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.data.hadoop.hbase.HbaseTemplate;
    import org.springframework.stereotype.Service;
    
    import com.zql.hbasedemo.vo.Quote;
    
    @Service
    public class FeedService {
        @Autowired
        private HbaseTemplate hbaseTemplate;
    
        @PostConstruct
        public void test(){
            Quote quote = new Quote();
            quote.setEventType("ft");
            quote.setHandicap("4");
            quote.setMarket("OU");
            quote.setMatchId("27350208");
            quote.setSelection("OVER");
            quote.setPrice("1.93");
            saveQuote(quote);
        }
    
        public void saveQuote(Quote quote) {
            hbaseTemplate.put("quotes", quote.getMatchId(), "data", quote.getMarket() + ":" + quote.getSelection(),
                quote.getPrice().getBytes());
        }
    }
    

    즐겨! :)

  5. ==============================

    5.github에서 spring-hadoop 샘플, 특히 spring-hadoop-samples / original-samples / hbase-crud의 파일을 확인할 수 있습니다. 저장소는 https://github.com/SpringSource/spring-hadoop-samples에 있습니다.

    github에서 spring-hadoop 샘플, 특히 spring-hadoop-samples / original-samples / hbase-crud의 파일을 확인할 수 있습니다. 저장소는 https://github.com/SpringSource/spring-hadoop-samples에 있습니다.

    희망이 당신을 도와줍니다.

  6. from https://stackoverflow.com/questions/24795097/how-to-use-hbase-with-spring-boot-using-java-instead-of-xml by cc-by-sa and MIT license