使用Spring-boot小结

Spring-boot的特点是,通过注入的方式生成FsShell对象,来操作HDFS,其底层封装了HDFS的的shell命令

1. 添加Spring-boot依赖

pom.xml文件

 <!--添加spring-boot依赖-->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-hadoop-boot</artifactId>
            <version>2.5.0.RELEASE</version>
        </dependency>

2.上代码

//添加注解,表名是SpringBoot应用
@SpringBootApplication
public class SpringBootApp implements CommandLineRunner {

    //通过注入方式得到FsShell
    @Autowired
    FsShell mFsShell;


    public void run(String... strings) throws Exception {
        Collection<FileStatus> fileStatuses = mFsShell.lsr("/");
        for (FileStatus fileStatus : fileStatuses) {
            System.out.println(">  " + fileStatus.getPath());
        }
    }

    public static void main(String[] agrs) {
        //通过SpringApplication来执行run方法
        SpringApplication.run(SpringBootApp.class, agrs);
    }
}
posted @ 2018-01-31 00:08  骑猪去流浪  阅读(874)  评论(0编辑  收藏  举报