简体   繁体   English

java.lang.IllegalStateException: Failed to load ApplicationContext: snakeyaml 依赖问题

[英]java.lang.IllegalStateException: Failed to load ApplicationContext: snakeyaml dependency issue

Due to snakeyaml vulnerability, I am trying to exclude it in spring-boot-starter-web using exclusions由于 snakeyaml 漏洞,我试图使用排除在 spring-boot-starter-web 中排除它

dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.yaml</groupId>
                <artifactId>snakeyaml</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

I have a testcase which uses @ContextConfiguration tag from springboot我有一个使用来自 springboot 的 @ContextConfiguration 标签的测试用例

@SpringBootTest
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = MongoConfig.class)
public class MongoConfigTest {
MongoConfig classUnderTest = new MongoConfig(); ...

This testcase is failing due to below error:由于以下错误,此测试用例失败:

<error message="Failed to load ApplicationContext" 
    type="java.lang.IllegalStateException">java.lang.IllegalStateException: Failed to load 
    ApplicationContext
    Caused by: java.lang.IllegalStateException: Attempted to load Config resource 'class path 
    resource [application.yml]' via location 'optional:classpath:/' but snakeyaml was not 
    found on the classpath
  </error>

How to resolve this issue?如何解决这个问题?

Spring-Boot version: 2.5.13
java: 11

I removed these three tags which was responsible for loading the application context我删除了这三个负责加载应用程序上下文的标签

@SpringBootTest
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = MongoConfig.class)

This worked for me.这对我有用。 Is there any better way to tackle this issue?有没有更好的方法来解决这个问题?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.IllegalStateException:无法加载ApplicationContext - java.lang.IllegalStateException: Failed to load ApplicationContext Junit错误:java.lang.IllegalStateException:无法加载ApplicationContext - Junit error :java.lang.IllegalStateException: Failed to load ApplicationContext Spring JUnit-java.lang.IllegalStateException:无法加载ApplicationContext - Spring JUnit - java.lang.IllegalStateException: Failed to load ApplicationContext 测试失败:java.lang.IllegalStateException:加载ApplicationContext失败 - Test Failure : java.lang.IllegalStateException: Failed to load ApplicationContext SpringBoot + Mybatis + MySQL,java.lang.IllegalStateException:无法加载ApplicationContext - SpringBoot + Mybatis + MySQL, java.lang.IllegalStateException: Failed to load ApplicationContext 测试 java.lang.IllegalStateException: 加载 ApplicationContext 失败 - Test java.lang.IllegalStateException: Failed to load ApplicationContext @WebMvcTest 失败,出现 java.lang.IllegalStateException:无法加载 ApplicationContext - @WebMvcTest fails with java.lang.IllegalStateException: Failed to load ApplicationContext java.lang.IllegalStateException:无法加载 ApplicationContext 错误 java spring-boot - java.lang.IllegalStateException: Failed to load ApplicationContext error java spring-boot Java Spring 测试没有 Spring 启动 - 错误 Z93F725A07423FE1C8846F448IllegalZlangException:FFailed 加载应用程序。 - Java Spring testing without Spring Boot - error java.lang.IllegalStateException: Failed to load ApplicationContext 使用@SpringBootTest 时如何修复“java.lang.IllegalStateException: Failed to load ApplicationContext” - How to fix “java.lang.IllegalStateException: Failed to load ApplicationContext” when using @SpringBootTest
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM