开发者

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

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

@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开发者_Go百科 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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜