淘先锋技术网

首页 1 2 3 4 5 6 7

问题场景:

在spring-boot中封装使用hbase模版类进行测试的是运行出现这个问题。

报错信息为: 

 报错描述:

java.io.FileNotFoundException: java.io.FileNotFoundException: HADOOP_HOME and hadoop.home.dir are unset. -see https://wiki.apache.org/hadoop/WindowsProblems
	at org.apache.hadoop.util.Shell.fileNotFoundException(Shell.java:534) ~[hadoop-common-2.10.0.jar:na]
	at org.apache.hadoop.util.Shell.getHadoopHomeDir(Shell.java:555) ~[hadoop-common-2.10.0.jar:na]
	at org.apache.hadoop.util.Shell.getQualifiedBin(Shell.java:578) ~[hadoop-common-2.10.0.jar:na]
	at org.apache.hadoop.util.Shell.<clinit>(Shell.java:675) ~[hadoop-common-2.10.0.jar:na]
	at org.apache.hadoop.util.StringUtils.<clinit>(StringUtils.java:78) ~[hadoop-common-2.10.0.jar:na]
	at org.apache.hadoop.conf.Configuration.getBoolean(Configuration.java:1567) ~[hadoop-common-2.10.0.jar:na]
	at org.apache.hadoop.hbase.HBaseConfiguration.checkDefaultsVersion(HBaseConfiguration.java:70) ~[hbase-common-2.4.3.jar:2.4.3]
	at org.apache.hadoop.hbase.HBaseConfiguration.addHbaseResources(HBaseConfiguration.java:84) ~[hbase-common-2.4.3.jar:2.4.3]
	at org.apache.hadoop.hbase.HBaseConfiguration.create(HBaseConfiguration.java:98) ~[hbase-common-2.4.3.jar:2.4.3]
	at com.adn.common.config.HbaseConfig.configuration(HbaseConfig.java:25) ~[classes/:na]
	at com.adn.common.config.HbaseConfig$$EnhancerBySpringCGLIB$$6a048ea8.CGLIB$configuration$0(<generated>) ~[classes/:na]
	at com.adn.common.config.HbaseConfig$$EnhancerBySpringCGLIB$$6a048ea8$$FastClassBySpringCGLIB$$1864e4a.invoke(<generated>) ~[classes/:na]
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.3.14.jar:5.3.14]
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.3.14.jar:5.3.14]
	at com.adn.common.config.HbaseConfig$$EnhancerBySpringCGLIB$$6a048ea8.configuration(<generated>) ~[classes/:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[spring-beans-5.3.14.jar:5.3.14]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.14.jar:5.3.14]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.14.jar:5.3.14]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.2.jar:2.6.2]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) ~[spring-boot-2.6.2.jar:2.6.2]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) ~[spring-boot-2.6.2.jar:2.6.2]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) ~[spring-boot-2.6.2.jar:2.6.2]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.2.jar:2.6.2]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290) ~[spring-boot-2.6.2.jar:2.6.2]
	at com.adn.HbaseApplication.main(HbaseApplication.java:9) ~[classes/:na]
Caused by: java.io.FileNotFoundException: HADOOP_HOME and hadoop.home.dir are unset.
	at org.apache.hadoop.util.Shell.checkHadoopHomeInner(Shell.java:454) ~[hadoop-common-2.10.0.jar:na]
	at org.apache.hadoop.util.Shell.checkHadoopHome(Shell.java:425) ~[hadoop-common-2.10.0.jar:na]
	at org.apache.hadoop.util.Shell.<clinit>(Shell.java:502) ~[hadoop-common-2.10.0.jar:na]
	... 36 common frames omitted

问题定位:

这个错误通常发生在你的应用程序中缺少设置Hadoop的环境变量或属性的情况下。要解决这个问题,你需要确保设置了正确的Hadoop环境变量或属性。

错误消息指出HADOOP_HOME和hadoop.home.dir未设置。这些通常是Hadoop所需的两个重要环境变量。HADOOP_HOME指示Hadoop安装的目录,而hadoop.home.dir指示Hadoop家目录。如果这些环境变量未设置或设置不正确,应用程序无法找到所需的Hadoop配置文件和库。

要解决这个问题,你可以采取以下步骤之一:

  1. 设置HADOOP_HOME环境变量:将HADOOP_HOME设置为指向正确的Hadoop安装目录路径。你可以通过修改操作系统的环境变量来实现这一点。具体的设置方法取决于你使用的操作系统。
  2. 设置hadoop.home.dir属性:如果你无法设置HADOOP_HOME环境变量,你可以在应用程序中设置hadoop.home.dir属性。可以在应用程序代码中添加以下语句:System.setProperty("hadoop.home.dir", "your_hadoop_home_directory"),将"your_hadoop_home_directory"替换为你的Hadoop安装目录的实际路径。

请注意,你需要确保Hadoop的安装目录和配置文件正确设置,以便应用程序可以找到并使用Hadoop。

问题解决:

1、环境的压缩包

GitHub - s911415/apache-hadoop-3.1.0-winutils: HADOOP 3.1.0 winutils

 2、配置环境变量

首先将压缩包解压

 包含bin文件目录

添加在环境变量中

   

重启idea 重启电脑尝试一下

问题就解决了!!!!