博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java里的ClassNotFoundException
阅读量:4230 次
发布时间:2019-05-26

本文共 2831 字,大约阅读时间需要 9 分钟。

1.Caused by: java.lang.ClassNotFoundException: org.springframework.security.oauth2.common.util.RandomValueStringGenerator

ClassNotFoundException是一个非运行时异常,且常常出现在项目启动时。它的意思简单明了,就是指项目启动时,或者执行某一个功能时,需要的Class找不到。这个错误非常常见,个人已经遇到过多次,但是每次的原因都不一定相同,

笔者这次遇到在使用springboot2.0的security相关配置时,启动时服务器报错,报错信息如下

Caused by: java.lang.NoClassDefFoundError: org/springframework/security/oauth2/common/util/RandomValueStringGenerator	at org.cloudfoundry.identity.uaa.util.CachingPasswordEncoder.
(CachingPasswordEncoder.java:71) at com.sap.ngom.datamigration.configuration.WebSecurityConfig.passwordEncoder(WebSecurityConfig.java:45) at com.sap.ngom.datamigration.configuration.WebSecurityConfig$$EnhancerBySpringCGLIB$$7b6105f3.CGLIB$passwordEncoder$2(
) at com.sap.ngom.datamigration.configuration.WebSecurityConfig$$EnhancerBySpringCGLIB$$7b6105f3$$FastClassBySpringCGLIB$$70546e9b.invoke(
) at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361) at com.sap.ngom.datamigration.configuration.WebSecurityConfig$$EnhancerBySpringCGLIB$$7b6105f3.passwordEncoder(
) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ... 53 common frames omittedCaused by: java.lang.ClassNotFoundException: org.springframework.security.oauth2.common.util.RandomValueStringGenerator at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 65 common frames omitted

从最后打出的log来看,就是org.springframework.security.oauth2.common.util这个包下面的RandomValueStringGenerator类找不到,导致了这个错误,但是笔者在用oauth2相关配置之前,已经在maven里面引入了相关的依赖,如下:

org.springframework.cloud
spring-cloud-starter-oauth2

且pom也没有报错,但是再次检查pom发现有下面这个现象:

因此判定解决这个unknown问题应该就能解决这个问题,准确的说还是依赖的问题导致需要的类找不到。最终通过修改pom中的依赖解决了这个问题。具体pom的修改这里不再展开。

2 spring-boot启动不了,报错 java.lang.NoClassDefFoundError: javax/servlet/ServletContext

pom配置文件中更改一下配置即可,

org.springframework.boot
spring-boot-starter-tomcat
provided

把scopt注释掉即可.

另一次遇到这个错误是在升级到spring boot2.1.5之后,解决办法:将dependency management里面的依赖去掉就没错误了。推测原因是升级会用到新的package,但是management里面指定的version没有这个class了。

参考 

 

转载地址:http://pjpqi.baihongyu.com/

你可能感兴趣的文章
后Hadoop时代的大数据架构
查看>>
浅谈开源大数据平台的演变
查看>>
Spark编程指南——Python版
查看>>
从零教你在Linux环境下(ubuntu 12.04)如何编译hadoop2.4
查看>>
Cloudera Hadoop开源组件Sentry:为金融、政府、医疗保健使用hadoop打下基础
查看>>
Java JDBC连接SQL Server2005错误:通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败
查看>>
Linux启动Tomcat服务
查看>>
Rattle :基于R的数据挖掘工具:简介和安装
查看>>
Rattle :基于R的数据挖掘工具:功能概览
查看>>
通过eclipse查看、阅读hadoop2.4源码
查看>>
离线安装Cloudera Manager5.3.4与CDH5.3.4
查看>>
关于一些弹出对话框的提示
查看>>
文件下载问题
查看>>
ASP.NET返回上一页的方法小集
查看>>
超链接,根据条件使得超链接显示与否
查看>>
RegisterClientScriptBlock 与 RegisterStartupScript的使用与区别
查看>>
SQLServer中Partition By 函数的使用
查看>>
vscode-Live Server的使用心得
查看>>
Error: listen EACCES 0.0.0.0:8080
查看>>
键盘键值表
查看>>