Spring Boot @SpringBootTest提供了NoClassDefFoundError:... DataAccessException

时间:2018-11-13 15:52:49

标签: java spring spring-boot

我无法解决此问题。我有一个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     在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。类];嵌套的异常是java.lang.NoClassDefFoundError:org / springframework / dao / DataAccessException

1 个答案:

答案 0 :(得分:0)

对不起,经过更多调查后,我发现问题出在我的FilterRegistrationBean中。

被揭发了。

ClassPathScanningCandidateComponentProvider provider = createComponentScanner();
provider.findCandidateComponents("").stream()...

我将回答该主题并创建一个新主题。