由于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
1条答案
按热度按时间ijnw1ujt1#
我删除了这三个负责加载应用程序上下文的标记
这对我很有效。有没有更好的方法来解决这个问题?