SpringBoot项目报错之java.lang.IllegalStateException: Failed to load ApplicationContext

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call the method springfox.documentation.swagger.web.UiConfigurationBuilder.supportedSubmitMethods([Ljava/lang/String;)Lspringfox/documentation/swagger/web/UiConfigurationBuilder; but it does not exist. Its class, springfox.documentation.swagger.web.UiConfigurationBuilder, is available from the following locations:

    jar:file:/Users/zhangmengjie/Documents/devTool/maven/mavenRepository/io/springfox/springfox-swagger-common/2.8.0/springfox-swagger-common-2.8.0.jar!/springfox/documentation/swagger/web/UiConfigurationBuilder.class

It was loaded from the following location:

    file:/Users/zhangmengjie/Documents/devTool/maven/mavenRepository/io/springfox/springfox-swagger-common/2.8.0/springfox-swagger-common-2.8.0.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of springfox.documentation.swagger.web.UiConfigurationBuilder

2020-02-19 14:29:35.832 ERROR 1544 --- [           main] o.s.test.context.TestContextManager      : Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@510da778] to prepare test instance [com.unicom.microserv.skyark.component.sample.web.SkyarkBasicDemoApplicationTest@1177e2c4]

java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125)
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108)
    at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190)
    at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:246)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:365)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:273)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:159)
    at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:383)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:344)
    at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:125)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:417)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'apiResourceController': Unsatisfied dependency expressed through field 'uiConfiguration'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uiConfig' defined in class path resource [com/unicom/skyark/component/web/config/SwaggerConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [springfox.documentation.swagger.web.UiConfiguration]: Factory method 'uiConfig' threw exception; nested exception is java.lang.NoSuchMethodError: springfox.documentation.swagger.web.UiConfigurationBuilder.supportedSubmitMethods([Ljava/lang/String;)Lspringfox/documentation/swagger/web/UiConfigurationBuilder;
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:374)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1378)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:575)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:846)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
    at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:127)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
    ... 27 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uiConfig' defined in class path resource [com/unicom/skyark/component/web/config/SwaggerConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [springfox.documentation.swagger.web.UiConfiguration]: Factory method 'uiConfig' threw exception; nested exception is java.lang.NoSuchMethodError: springfox.documentation.swagger.web.UiConfigurationBuilder.supportedSubmitMethods([Ljava/lang/String;)Lspringfox/documentation/swagger/web/UiConfigurationBuilder;
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1288)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:273)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1237)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1164)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:593)
    ... 45 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [springfox.documentation.swagger.web.UiConfiguration]: Factory method 'uiConfig' threw exception; nested exception is java.lang.NoSuchMethodError: springfox.documentation.swagger.web.UiConfigurationBuilder.supportedSubmitMethods([Ljava/lang/String;)Lspringfox/documentation/swagger/web/UiConfigurationBuilder;
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622)
    ... 58 common frames omitted
Caused by: java.lang.NoSuchMethodError: springfox.documentation.swagger.web.UiConfigurationBuilder.supportedSubmitMethods([Ljava/lang/String;)Lspringfox/documentation/swagger/web/UiConfigurationBuilder;
    at com.unicom.skyark.component.web.config.SwaggerConfig.uiConfig(SwaggerConfig.java:90)
    at com.unicom.skyark.component.web.config.SwaggerConfig$$EnhancerBySpringCGLIB$$64e9b651.CGLIB$uiConfig$1(<generated>)
    at com.unicom.skyark.component.web.config.SwaggerConfig$$EnhancerBySpringCGLIB$$64e9b651$$FastClassBySpringCGLIB$$b4253eab.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363)
    at com.unicom.skyark.component.web.config.SwaggerConfig$$EnhancerBySpringCGLIB$$64e9b651.uiConfig(<generated>)
    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)
    ... 59 common frames omitted

[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 9.429 s <<< FAILURE! - in com.unicom.microserv.skyark.component.sample.web.SkyarkBasicDemoApplicationTest
[ERROR] testModule(com.unicom.microserv.skyark.component.sample.web.SkyarkBasicDemoApplicationTest)  Time elapsed: 0.002 s  <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'apiResourceController': Unsatisfied dependency expressed through field 'uiConfiguration'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uiConfig' defined in class path resource [com/unicom/skyark/component/web/config/SwaggerConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [springfox.documentation.swagger.web.UiConfiguration]: Factory method 'uiConfig' threw exception; nested exception is java.lang.NoSuchMethodError: springfox.documentation.swagger.web.UiConfigurationBuilder.supportedSubmitMethods([Ljava/lang/String;)Lspringfox/documentation/swagger/web/UiConfigurationBuilder;
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uiConfig' defined in class path resource [com/unicom/skyark/component/web/config/SwaggerConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [springfox.documentation.swagger.web.UiConfiguration]: Factory method 'uiConfig' threw exception; nested exception is java.lang.NoSuchMethodError: springfox.documentation.swagger.web.UiConfigurationBuilder.supportedSubmitMethods([Ljava/lang/String;)Lspringfox/documentation/swagger/web/UiConfigurationBuilder;
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [springfox.documentation.swagger.web.UiConfiguration]: Factory method 'uiConfig' threw exception; nested exception is java.lang.NoSuchMethodError: springfox.documentation.swagger.web.UiConfigurationBuilder.supportedSubmitMethods([Ljava/lang/String;)Lspringfox/documentation/swagger/web/UiConfigurationBuilder;
Caused by: java.lang.NoSuchMethodError: springfox.documentation.swagger.web.UiConfigurationBuilder.supportedSubmitMethods([Ljava/lang/String;)Lspringfox/documentation/swagger/web/UiConfigurationBuilder;

[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Errors: 
[ERROR]   SkyarkBasicDemoApplicationTest.testModule » IllegalState Failed to load Applic...
[INFO] 
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  15.514 s
[INFO] Finished at: 2020-02-19T14:29:36+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.0:test (default-test) on project skyark_component_sample_web: There are test failures.
[ERROR] 
[ERROR] Please refer to /Users/zhangmengjie/Documents/workspaces/IDEASpace2019/skyark_component_sample/skyark_component_sample_web/target/surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Process finished with exit code 1

好的,你提到的问题是关于SpringBoot项目测试类报错java.lang.IllegalStateException: Failed to load ApplicationContext。这个错误通常表示Spring框架在尝试加载你的应用程序上下文时遇到了问题。这可能是由于多种原因导致的,下面是一些可能的解决方案: 1. **配置文件问题**:确保你的Spring Boot配置文件(如application.properties或application.yml)正确配置,并且没有语法错误。 2. **依赖问题**:确保你的项目依赖项都已正确添加,并且版本兼容。有时候,不同版本的Spring Boot或相关库之间可能存在兼容性问题。 3. **环境变量问题**:如果你使用了环境变量来配置某些属性,确保它们被正确设置。 4. **测试类配置问题**:如果你在测试类中使用了自定义配置,请确保这些配置是正确的,并且已经正确加载。 5. **循环依赖**:确保你的应用程序没有循环依赖问题。如果有,你需要重新设计你的应用程序结构以消除循环依赖。 6. **事务管理问题**:如果你在测试类中使用了事务管理,确保你正确地关闭了事务。你可以使用`@Transactional(noRollback = true)`注解来关闭事务。 7. **Bean创建失败**:有时候,Spring无法创建某些Bean可能会导致这个错误。检查你的Bean定义,确保它们没有语法错误,并且所有必需的依赖都已正确注入。 8. **测试环境配置问题**:如果你在测试类中使用了特定的配置(如数据库连接),请确保这些配置文件存在并且正确配置。 如果以上建议都不能解决你的问题,请提供更详细的错误信息或代码片段,这样我可以更准确地帮助你找到问题所在。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

渣渣梦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值