spring java.lang.IllegalStateException:无法加载应用程序上下文:snakeyaml依赖关系问题

ddrv8njm  于 2022-12-10  发布在  Spring
关注(0)|答案(1)|浏览(388)

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

我有一个使用springboot中的@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
ijnw1ujt

ijnw1ujt1#

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

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

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

相关问题