最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Hadoop集成Spring的使用詳細(xì)教程(快速入門大數(shù)據(jù))

 更新時(shí)間:2021年01月22日 09:46:12   作者:瑞 新  
這篇文章主要介紹了Hadoop集成Spring的使用詳細(xì)教程(快速入門大數(shù)據(jù)),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

官網(wǎng)sprng-hadoop

https://spring.io/projects/spring-hadoop

添加依賴

<dependencies>
 <dependency>
  <groupId>org.springframework.data</groupId>
  <artifactId>spring-data-hadoop</artifactId>
  <version>2.5.0.RELEASE</version>
 </dependency>
</dependencies>

使用spring hadoop配置及查看HDFS文件

新建資源文件beans.xml

在這里插入圖片描述

<?xml version="1.0" encoding="UTF-8"?>
<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:configuration id="hadoopConfiguration">
  fs.defaultFS=hdfs://hadoop01:9000
  hadoop.tmp.dir=/tmp/hadoop
  electric=sea
 </hdp:configuration>

 <hdp:file-system id="fileSystem"
      configuration-ref="hadoopConfiguration"
      user="root"
 />

</beans>

測(cè)試文件

package com.bennyrhys.hadoop.spring;

import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.IOException;

/**
 * @Author bennyrhys
 * @Date 1/21/21 2:35 PM
 */
public class SpringHadoopHDFSApp {
 private ApplicationContext ctx;
 // apache hadoop
 private FileSystem fileSystem;

 /**
  * 創(chuàng)建HDFS文件夾
  */
 @Test
 public void testMkdirs() throws Exception {
  fileSystem.mkdirs(new Path("/springhdfs"));
 }

 /**
  * 查看HDFS文件
  */
 @Test
 public void testText() throws Exception {
  FSDataInputStream in = fileSystem.open(new Path("/springhdfs/hello.txt"));
  IOUtils.copyBytes(in, System.out, 1024);
  in.close();
 }

 @Before
 public void setUp() {
  ctx = new ClassPathXmlApplicationContext("beans.xml");
  fileSystem = (FileSystem) ctx.getBean("fileSystem");
 }

 @After
 public void tearDown() throws Exception {
  ctx = null;
  fileSystem.close();
 }
}

spring hadoop 配置文件詳解

提取變量

使用xml中的頭文件替換bean,使其允許使用上下文
${}導(dǎo)入變量

新建配置文件application.properties

spring.hadoop.fsUri=hdfs://hadoop01:9000

獲取context上下文引入變量
beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<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"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
  http://www.springframework.org/schema/hadoop http://www.springframework.org/schema/hadoop/spring-hadoop.xsd">

 <hdp:configuration id="hadoopConfiguration">
  fs.defaultFS=${spring.hadoop.fsUri}
  hadoop.tmp.dir=/tmp/hadoop
  electric=sea
 </hdp:configuration>
 <context:property-placeholder location="application.properties"/>

 <hdp:file-system id="fileSystem"
      configuration-ref="hadoopConfiguration"
      user="root"
 />

</beans>

SpringBoot訪問(wèn)HDFS系統(tǒng)

pom.xml

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

SpringBootHDFSApp

package com.bennyrhys.hadoop.spring;

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;

/**
 * @Author bennyrhys
 * @Date 1/21/21 11:33 PM
 */
@SpringBootApplication
public class SpringBootHDFSApp implements CommandLineRunner {

 @Autowired
 FsShell fsShell; //引入spring的

 @Override
 public void run(String... strings) throws Exception {
  for (FileStatus fileStatus : fsShell.lsr("/springhdfs")) {
   System.out.println("> " + fileStatus.getPath());
  }
 }

 /**
  * > hdfs://hadoop01:9000/springhdfs
  * > hdfs://hadoop01:9000/springhdfs/hello.txt
  * @param args
  */
 public static void main(String[] args) {
  SpringApplication.run(SpringBootHDFSApp.class, args);
 }
}

到此這篇關(guān)于Hadoop集成Spring的使用詳細(xì)教程(快速入門大數(shù)據(jù))的文章就介紹到這了,更多相關(guān)Hadoop集成Spring的使用內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • java解析php函數(shù)json_encode unicode 編碼問(wèn)題

    java解析php函數(shù)json_encode unicode 編碼問(wèn)題

    這篇文章主要介紹了java解析php函數(shù)json_encode unicode 編碼問(wèn)題,需要的朋友可以參考下
    2016-04-04
  • Java8 用Lambda表達(dá)式給List集合排序的實(shí)現(xiàn)

    Java8 用Lambda表達(dá)式給List集合排序的實(shí)現(xiàn)

    這篇文章主要介紹了Java8 用Lambda表達(dá)式給List集合排序的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08
  • 基于eclipse-temurin鏡像部署spring boot應(yīng)用的實(shí)現(xiàn)示例

    基于eclipse-temurin鏡像部署spring boot應(yīng)用的實(shí)現(xiàn)示例

    本文提供了基于eclipse-temurin鏡像部署Spring Boot應(yīng)用的詳細(xì)實(shí)現(xiàn)示例,通過(guò)使用Docker鏡像,可以輕松地創(chuàng)建和管理Spring Boot應(yīng)用程序的容器化環(huán)境,感興趣的可以了解一下
    2023-08-08
  • Java實(shí)現(xiàn)二叉樹的建立、計(jì)算高度與遞歸輸出操作示例

    Java實(shí)現(xiàn)二叉樹的建立、計(jì)算高度與遞歸輸出操作示例

    這篇文章主要介紹了Java實(shí)現(xiàn)二叉樹的建立、計(jì)算高度與遞歸輸出操作,結(jié)合實(shí)例形式分析了Java二叉樹的創(chuàng)建、遍歷、計(jì)算等相關(guān)算法實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2019-03-03
  • java實(shí)現(xiàn)插入排序算法

    java實(shí)現(xiàn)插入排序算法

    插入排序算法是一個(gè)對(duì)少量元素進(jìn)行排序的有效算法。插入排序的工作原理與打牌時(shí)整理手中的牌的做法類似,開始摸牌時(shí),我們的左手是空的,接著一次從桌上摸起一張牌,并將它插入到左手的正確位置。
    2015-04-04
  • Spring中的@ExceptionHandler注解統(tǒng)一異常處理詳解

    Spring中的@ExceptionHandler注解統(tǒng)一異常處理詳解

    這篇文章主要介紹了Spring中的@ExceptionHandler注解統(tǒng)一異常處理詳解,當(dāng)我們使用這個(gè)@ExceptionHandler注解時(shí),定義一個(gè)異常的處理方法,加上@ExceptionHandler注解,這個(gè)方法就會(huì)處理類中其他方法拋出的異常,需要的朋友可以參考下
    2024-01-01
  • Spring Boot超詳細(xì)分析啟動(dòng)流程

    Spring Boot超詳細(xì)分析啟動(dòng)流程

    SpringBoot是Spring開源組織下的子項(xiàng)目,是Spring組件一站式解決方案,主要是簡(jiǎn)化了使用Spring的難度,簡(jiǎn)省了繁重的配置,提供了各種啟動(dòng)器,開發(fā)者能快速上手,這篇文章主要給大家介紹了關(guān)于Spring Boot啟動(dòng)流程知識(shí)點(diǎn)的相關(guān)資料,需要的朋友可以參考下
    2022-07-07
  • Java反射機(jī)制的學(xué)習(xí)總結(jié)

    Java反射機(jī)制的學(xué)習(xí)總結(jié)

    總的來(lái)說(shuō),java反射機(jī)制是一個(gè)很好用的東西,用它可以解決很多死的東西,因?yàn)榉瓷錂C(jī)制的靈活行很大,有了他,我們就不要花太多的時(shí)間來(lái)寫操做數(shù)據(jù)庫(kù)的代碼了,而是方法更多的時(shí)間在項(xiàng)目的邏輯功能上,這個(gè)可以很大的減少開發(fā)時(shí)間,而且代碼的可讀性好
    2013-09-09
  • 詳解Spring?Bean的配置方式與實(shí)例化

    詳解Spring?Bean的配置方式與實(shí)例化

    本文主要帶大家一起學(xué)習(xí)一下Spring?Bean的配置方式與實(shí)例化,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Spring有一定的幫助,需要的可以參考一下
    2022-06-06
  • Springboot+MybatisPlus實(shí)現(xiàn)帶驗(yàn)證碼的登錄

    Springboot+MybatisPlus實(shí)現(xiàn)帶驗(yàn)證碼的登錄

    本文主要介紹了Springboot+MybatisPlus實(shí)現(xiàn)帶驗(yàn)證碼的登錄,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2024-05-05

最新評(píng)論

建水县| 永安市| 黎城县| 若尔盖县| 民乐县| 邵阳县| 青海省| 宣化县| 蓬莱市| 大渡口区| 长岭县| 兴国县| 中方县| 三台县| 康乐县| 金山区| 文水县| 大厂| 林甸县| 乌海市| 富蕴县| 洛南县| 柏乡县| 秦安县| 韶关市| 利川市| 洞头县| 邢台县| 思茅市| 万源市| 四子王旗| 唐山市| 卢氏县| 平湖市| 山东| 潼南县| 昆山市| 垫江县| 松溪县| 广安市| 大方县|