美文网首页
Hadoop和Springboot集成

Hadoop和Springboot集成

作者: 神豪VS勇士赢 | 来源:发表于2020-07-27 23:53 被阅读0次

    1.引入依赖

        <!--添加spring boot 依赖-->
        <dependency>
          <groupId>org.springframework.data</groupId>
          <artifactId>spring-data-hadoop-boot</artifactId>
          <version>RELEASE</version>
        </dependency>
    
    1. 便携式配置类 注入 FsShell 可以快速操作
    package com.imooc.hadoop.spring;
    /*
     * Created by zsh
     */
    
    import org.apache.hadoop.fs.FileStatus;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.CommandLineRunner;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.data.hadoop.fs.FsShell;
    
    /**
     * 使用Spring Boot访问HDFS
     */
    @SpringBootApplication
    public class SpringBootHDFSApp implements CommandLineRunner {
    
        @Autowired
        FsShell fsShell;
    
    
        @Override
        public void run(String... strings) throws Exception {
    
            System.out.println("=========start===========");
    
            for (FileStatus fileStatus : fsShell.lsr("/springhdfs")) {
                System.out.println("> " + fileStatus.getPath());
            }
    
            System.out.println("=========end===========");
    
        }
    
        public static void main(String args[]) {
            SpringApplication.run(SpringBootHDFSApp.class ,args);
        }
    
    }
    
    1. 详细看文档
      https://spring.io/projects/spring-hadoop
    image.png

    相关文章

      网友评论

          本文标题:Hadoop和Springboot集成

          本文链接:https://www.haomeiwen.com/subject/okkxrktx.html