【问题标题】:java.lang.IllegalStateException: Failed to load ApplicationContext: snakeyaml dependency issuejava.lang.IllegalStateException: Failed to load ApplicationContext: snakeyaml 依赖问题
【发布时间】:2022-12-07 15:54:46
【问题描述】:

由于 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>

我有一个测试用例,它使用来自 spring boot 的 @ContextConfiguration 标签

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

由于以下错误,此测试用例失败:

<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>

如何解决这个问题?

Spring-Boot version: 2.5.13
java: 11

【问题讨论】:

    标签: java spring spring-boot maven snakeyaml


    【解决方案1】:

    我删除了这三个负责加载应用程序上下文的标签

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

    这对我有用。有没有更好的方法来解决这个问题?

    【讨论】:

      猜你喜欢
      • 2021-07-30
      • 1970-01-01
      • 2021-12-01
      • 1970-01-01
      • 2018-09-22
      • 1970-01-01
      • 2021-12-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多