当前位置:   article > 正文

Hbase-spring-boot报错解决java.io.FileNotFoundException: HADOOP_HOME and hadoop.home.dir are unset.配置环境变量_springboot整合hadoop启动报错

springboot整合hadoop启动报错

问题场景:

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

报错信息为: 

 报错描述:

  1. java.io.FileNotFoundException: java.io.FileNotFoundException: HADOOP_HOME and hadoop.home.dir are unset. -see https://wiki.apache.org/hadoop/WindowsProblems
  2. at org.apache.hadoop.util.Shell.fileNotFoundException(Shell.java:534) ~[hadoop-common-2.10.0.jar:na]
  3. at org.apache.hadoop.util.Shell.getHadoopHomeDir(Shell.java:555) ~[hadoop-common-2.10.0.jar:na]
  4. at org.apache.hadoop.util.Shell.getQualifiedBin(Shell.java:578) ~[hadoop-common-2.10.0.jar:na]
  5. at org.apache.hadoop.util.Shell.<clinit>(Shell.java:675) ~[hadoop-common-2.10.0.jar:na]
  6. at org.apache.hadoop.util.StringUtils.<clinit>(StringUtils.java:78) ~[hadoop-common-2.10.0.jar:na]
  7. at org.apache.hadoop.conf.Configuration.getBoolean(Configuration.java:1567) ~[hadoop-common-2.10.0.jar:na]
  8. at org.apache.hadoop.hbase.HBaseConfiguration.checkDefaultsVersion(HBaseConfiguration.java:70) ~[hbase-common-2.4.3.jar:2.4.3]
  9. at org.apache.hadoop.hbase.HBaseConfiguration.addHbaseResources(HBaseConfiguration.java:84) ~[hbase-common-2.4.3.jar:2.4.3]
  10. at org.apache.hadoop.hbase.HBaseConfiguration.create(HBaseConfiguration.java:98) ~[hbase-common-2.4.3.jar:2.4.3]
  11. at com.adn.common.config.HbaseConfig.configuration(HbaseConfig.java:25) ~[classes/:na]
  12. at com.adn.common.config.HbaseConfig$$EnhancerBySpringCGLIB$$6a048ea8.CGLIB$configuration$0(<generated>) ~[classes/:na]
  13. at com.adn.common.config.HbaseConfig$$EnhancerBySpringCGLIB$$6a048ea8$$FastClassBySpringCGLIB$$1864e4a.invoke(<generated>) ~[classes/:na]
  14. at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.3.14.jar:5.3.14]
  15. at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.3.14.jar:5.3.14]
  16. at com.adn.common.config.HbaseConfig$$EnhancerBySpringCGLIB$$6a048ea8.configuration(<generated>) ~[classes/:na]
  17. at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
  18. at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
  19. at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
  20. at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
  21. at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.14.jar:5.3.14]
  22. at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.14.jar:5.3.14]
  23. at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486) ~[spring-beans-5.3.14.jar:5.3.14]
  24. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.14.jar:5.3.14]
  25. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.14.jar:5.3.14]
  26. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.14.jar:5.3.14]
  27. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.14.jar:5.3.14]
  28. at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.14.jar:5.3.14]
  29. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.14.jar:5.3.14]
  30. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.14.jar:5.3.14]
  31. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.14.jar:5.3.14]
  32. at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[spring-beans-5.3.14.jar:5.3.14]
  33. at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.14.jar:5.3.14]
  34. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.14.jar:5.3.14]
  35. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.2.jar:2.6.2]
  36. at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) ~[spring-boot-2.6.2.jar:2.6.2]
  37. at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) ~[spring-boot-2.6.2.jar:2.6.2]
  38. at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) ~[spring-boot-2.6.2.jar:2.6.2]
  39. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.2.jar:2.6.2]
  40. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290) ~[spring-boot-2.6.2.jar:2.6.2]
  41. at com.adn.HbaseApplication.main(HbaseApplication.java:9) ~[classes/:na]
  42. Caused by: java.io.FileNotFoundException: HADOOP_HOME and hadoop.home.dir are unset.
  43. at org.apache.hadoop.util.Shell.checkHadoopHomeInner(Shell.java:454) ~[hadoop-common-2.10.0.jar:na]
  44. at org.apache.hadoop.util.Shell.checkHadoopHome(Shell.java:425) ~[hadoop-common-2.10.0.jar:na]
  45. at org.apache.hadoop.util.Shell.<clinit>(Shell.java:502) ~[hadoop-common-2.10.0.jar:na]
  46. ... 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 重启电脑尝试一下

问题就解决了!!!! 

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号