springboot远程链接Hadoop

2.3、springboot远程链接Hadoop

1、依赖

xml 复制代码
<!--        Hadoop依赖-->
        <!-- Hadoop Client -->
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-client</artifactId>
            <version>3.3.1</version>
        </dependency>

2、yaml文件

yaml 复制代码
#HDFS配置
hdfs:
  path: hdfs://192.168.44.128:9000
  user: hadoop

3、安装配置winutils.exe

4、示例代码

  • controller层

    java 复制代码
    @RestController
    @RequestMapping("/test/hdfs")
    public class HdfsController {
     
        @Autowired
        private HdfsService service;
     
     
        @GetMapping("/mkdir")
        public String mkdir(String path){
            try {
                service.mkdir(path);
                return "1";
            } catch (Exception e) {
                System.out.print(e.toString());
                return "2";
            }
        }
    }
  • service层

    java 复制代码
        public boolean mkdir(String dir) throws Exception{
            if(StringUtils.isBlank(dir)){
                return false;
            }
            if(exist(dir)){
                return true;
            }
            FileSystem fileSystem = getFileSystem();
            boolean isOk = fileSystem.mkdirs(new Path(dir));
            fileSystem.close();
            return isOk;
        }
相关推荐
Victor3562 分钟前
Redis(133)Redis的对象共享机制是什么?
后端
Alang5 分钟前
【LM-PDF】一个大模型时代的 PDF 极速预览方案是如何实现的?
前端·人工智能·后端
Victor3565 分钟前
Redis(132) Redis的对象编码是什么?
后端
绝无仅有6 分钟前
某电商大厂技术面试场景解析
javascript·后端·面试
l***74946 分钟前
Spring Boot 中使用 @Transactional 注解配置事务管理
数据库·spring boot·sql
千里码aicood2 小时前
springboot+vue考研复习交流平台设计(源码+文档+调试+基础修改+答疑)
vue.js·spring boot·后端
csdn_wuwt5 小时前
前后端中Dto是什么意思?
开发语言·网络·后端·安全·前端框架·开发
JosieBook5 小时前
【Rust】 基于Rust 从零构建一个本地 RSS 阅读器
开发语言·后端·rust
王者之座7 小时前
java+maven配置yguard的一次实验
java·spring boot·maven
韩立学长8 小时前
基于Springboot的研学旅游服务系统5u416w14(程序、源码、数据库、调试部署方案及开发环境)系统界面展示及获取方式置于文档末尾,可供参考。
数据库·spring boot·旅游