使用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);
}
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步