解决nacos报错java.lang.ClassNotFoundException: com.netflix.config.DynamicPropertyFactory的问题
nacos报错java.lang.ClassNotFoundException: com.netflix.config.DynamicPropertyFactory
问题背景
使用LoadBalancerClient报错java.lang.ClassNotFoundException: com.netflix.config.DynamicPropertyFactory
java.lang.ClassNotFoundException: com.netflix.config.DynamicPropertyFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_221]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_221]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) ~[na:1.8.0_221]
解决方案
1 找不到类,说明没有引入这个依赖,然后看了一下nacos引入了,,但排除了很多依赖,这个核心被排除掉了,所以报错
<exclusion> <artifactId>archaius-core</artifactId> <groupId>com.netflix.archaius</groupId> </exclusion>
2 正常引入的依赖,因为引入了其他很多东西,所以排除了,很多根据自己需要把排除删除掉
<dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-nacos-discovery</artifactId> <version>2.2.0.RELEASE</version> <exclusions> <exclusion> <artifactId>guava</artifactId> <groupId>com.google.guava</groupId> </exclusion> <exclusion> <artifactId>HdrHistogram</artifactId> <groupId>org.hdrhistogram</groupId> </exclusion> <exclusion> <artifactId>spring-cloud-commons</artifactId> <groupId>org.springframework.cloud</groupId> </exclusion> <exclusion> <artifactId>commons-codec</artifactId> <groupId>commons-codec</groupId> </exclusion> <exclusion> <artifactId>commons-lang3</artifactId> <groupId>org.apache.commons</groupId> </exclusion> <exclusion> <artifactId>httpclient</artifactId> <groupId>org.apache.httpcomponents</groupId> </exclusion> <exclusion> <artifactId>spring-cloud-starter</artifactId> <groupId>org.springframework.cloud</groupId> </exclusion> </exclusions> </dependency>
nacos启动常见错误
1. Could not find or load main class
Error: Could not find or load main class
Caused by: java.lang.ClassNotFoundException:
解决办法:
x JAVA_OPT_EXT_FIX="-Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext"
√ JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext"
x echo "$JAVA $JAVA_OPT_EXT_FIX ${JAVA_OPT}"
√ echo "$JAVA ${JAVA_OPT}"
x echo "$JAVA $JAVA_OPT_EXT_FIX ${JAVA_OPT}" > ${BASE_DIR}/logs/start.out 2>&1 &
x nohup "$JAVA" "$JAVA_OPT_EXT_FIX" ${JAVA_OPT} nacos.nacos >> ${BASE_DIR}/logs/start.out 2>&1 &
√ echo "$JAVA ${JAVA_OPT}" > ${BASE_DIR}/logs/start.out 2>&1 &
√ nohup $JAVA ${JAVA_OPT} nacos.nacos >> ${BASE_DIR}/logs/start.out 2>&1 &
2. Please set the JAVA_HOME variable in your environment
which: no javac in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
readlink: missing operand
Try 'readlink --help' for more information.
dirname: missing operand
Try 'dirname --help' for more information.
ERROR: Please set the JAVA_HOME variable in your environment, We need java(x64)! jdk8 or later is better! !!
查找原因:
- 输入echo $JAVA_HOME结果为空
- 说明没有配置java环境变量
解决办法:
- 配置JAVA环境变量
2.1 找到jdk安装路径
[root@localhost bin]# ls -lrt /usr/bin/java
lrwxrwxrwx 1 root root 22 Mar 15 09:59 /usr/bin/java -> /etc/alternatives/java
[root@localhost bin]# ls -lrt /etc/alternatives/java
lrwxrwxrwx 1 root root 73 Mar 15 09:59 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/jre/bin/java
[root@localhost bin]# cd /usr/lib/jvm
[root@localhost jvm]# ll
total 4
drwxr-xr-x 3 root root 4096 Mar 15 09:59 java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64
lrwxrwxrwx 1 root root 21 Mar 15 09:59 jre -> /etc/alternatives/jre
lrwxrwxrwx 1 root root 27 Mar 15 09:59 jre-1.8.0 -> /etc/alternatives/jre_1.8.0
lrwxrwxrwx 1 root root 35 Mar 15 09:59 jre-1.8.0-openjdk -> /etc/alternatives/jre_1.8.0_openjdk
lrwxrwxrwx 1 root root 51 Mar 15 09:59 jre-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64 -> java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/jre
lrwxrwxrwx 1 root root 29 Mar 15 09:59 jre-openjdk -> /etc/alternatives/jre_openjdk
2.2 在/etc/profile文件下添加以下代码并执行
export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
[root@localhost ~]# source /etc/profile
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
Java中的字符流FileReader与FileWriter详解
这篇文章主要介绍了Java中的字符流FileReader与FileWriter详解,在Java中,使用Unicode约定存储字符,字符流自动允许我们逐字符读/写数据,有助于执行16位Unicode的输入和输出,它是以reader和writer结尾的,需要的朋友可以参考下2023-10-10Spring Boot项目利用Redis实现session管理实例
本篇文章主要介绍了Spring Boot项目利用Redis实现session管理实例,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-06-06教你在 Java 中实现 Dijkstra 最短路算法的方法
这篇文章主要教你在 Java 中实现 Dijkstra 最短路算法的方法,在实现最短路算法之前需要先实现带权有向图,文章中给大家介绍的非常详细,需要的朋友可以参考下2022-04-04
最新评论