java - Spring Boot @SpringBootTest 给出 NoClassDefFoundError: ...DataAccessException
问题描述
我无法解决这个问题。我有一个spring boot
应用程序。
带有注释的主类
@SpringBootApplication.
带有注释的测试类:
@RunWith(SpringRunner.class)
@SpringBootTest
一切都很好,直到我filter-configurer
在应用程序中添加一个类:
@Configuration
public class YadaYadaFilterConfigurer
{
@Bean
public FilterRegistrationBean<YadaYadaFilter> createYadaYadaFilter()
{...}
...
}
繁荣!
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.FilterRegistrationBean]:
...
nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL [jar:file:...org.springframework.boot/spring-boot-test-autoconfigure/2.0.6.RELEASE/b0eb15474e795850dfa59b01ee6a83d7a39e3645/spring-boot-test-autoconfigure-2.0.6.RELEASE.jar!/org/springframework/boot/test/autoconfigure/jdbc/JdbcTest.class]; nested exception is java.lang.NoClassDefFoundError: org/springframework/dao/DataAccessException
我的依赖:
dependencies {
implementation('org.springframework.boot:spring-boot-starter-web')
testImplementation('org.springframework.boot:spring-boot-starter-test')
}
一些澄清。剥离,以便我只有这个测试类:
@RunWith(SpringRunner.class)
@SpringBootTest
public class JsonvalidationApplicationTests {
@Test
public void contextLoads() {
}
}
如果注释掉 @SpringBootTest 那么一切正常。似乎这个注释引入了对更多依赖项的需求?
更多堆栈跟踪:
原因:org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.boot.web.servlet.FilterRegistrationBean]:工厂方法'createyadayadaFilter'抛出异常;嵌套异常是 org.springframework.beans.factory.BeanDefinitionStoreException:无法读取候选组件类:URL [jar:file:/C:/Users/66122872/.gradle/caches/modules-2/files-2.1/org.springframework .boot/spring-boot-test-autoconfigure/2.0.6.RELEASE/b0eb15474e795850dfa59b01ee6a83d7a39e3645/spring-boot-test-autoconfigure-2.0.6.RELEASE.jar!/org/springframework/boot/test/autoconfigure/jdbc/JdbcTest。班级]; 嵌套异常是 java.lang.NoClassDefFoundError: org/springframework/dao/DataAccessException at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java: 185) 在 org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:583) ... 67 更多原因:org.springframework.beans.factory.BeanDefinitionStoreException:无法读取候选组件类:URL [ jar:file:/C:/Users/66122872/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-test-autoconfigure/2.0.6.RELEASE/b0eb15474e795850dfa59b01ee6a83d7a39e3645/spring-boot -test-autoconfigure-2.0.6.RELEASE.jar!/org/springframework/boot/test/autoconfigure/jdbc/JdbcTest.class]; 嵌套异常是 java.lang.NoClassDefFoundError: org/springframework/dao/DataAccessException BeanDefinitionStoreException:无法读取候选组件类:URL [jar:file:/C:/Users/66122872/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-test-autoconfigure/ 2.0.6.RELEASE/b0eb15474e795850dfa59b01ee6a83d7a39e3645/spring-boot-test-autoconfigure-2.0.6.RELEASE.jar!/org/springframework/boot/test/autoconfigure/jdbc/JdbcTest.class];嵌套异常是 java.lang.NoClassDefFoundError: org/springframework/dao/DataAccessException BeanDefinitionStoreException:无法读取候选组件类:URL [jar:file:/C:/Users/66122872/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-test-autoconfigure/ 2.0.6.RELEASE/b0eb15474e795850dfa59b01ee6a83d7a39e3645/spring-boot-test-autoconfigure-2.0.6.RELEASE.jar!/org/springframework/boot/test/autoconfigure/jdbc/JdbcTest.class];嵌套异常是 java.lang.NoClassDefFoundError: org/springframework/dao/DataAccessException
解决方案
抱歉,经过更多调查后,我发现问题出在我的 FilterRegistrationBean 中。
在这里抛出异常。
ClassPathScanningCandidateComponentProvider provider = createComponentScanner();
provider.findCandidateComponents("").stream()...
我将回答这个线程并创建一个新线程。
推荐阅读
- java - Apache CXF 日志拦截器未在 Spring Boot 应用程序上的 Weblogic 上触发
- python - 从 2D 数组创建矢量化 numpy.meshgrid 以创建 3D 网格
- c# - 在 WPF 中声明图像来源的问题
- ios - Stop Present Push Notification while App is Inactive or in Background
- javascript - 在 JavaScript 中创建变量意味着值不会在应该更新的时候更新?
- swift - 如何使用已存储在字典中的先前视图控制器中的字典检索数据?
- ruby-on-rails - How to restrict a not empty field in ruby on rails active record where clause
- apache-spark - Avro 数据未转换 Spark
- reactjs - 使用 FireBase 从对象中获取数据
- elasticsearch - select time range using two fields