Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 虚拟应用程序上下文测试Spring Boot中的过滤器_Java_Spring_Spring Boot_Spring Test - Fatal编程技术网

Java 虚拟应用程序上下文测试Spring Boot中的过滤器

Java 虚拟应用程序上下文测试Spring Boot中的过滤器,java,spring,spring-boot,spring-test,Java,Spring,Spring Boot,Spring Test,我正在尝试测试我的一个过滤器,但我不确定如何配置SpringBootTest来使用它。是否有办法提供默认/虚拟ApplicationContext,因为此项目仅包含筛选器本身 package org.example.filters; 导入静态org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; 导入静态org.springframework.test.web.servlet.result.MockMvcR

我正在尝试测试我的一个过滤器,但我不确定如何配置SpringBootTest来使用它。是否有办法提供默认/虚拟ApplicationContext,因为此项目仅包含筛选器本身

package org.example.filters;
导入静态org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
导入静态org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
导入org.junit.jupiter.api.Test;
导入org.junit.jupiter.api.extension.extensedWith;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
导入org.springframework.boot.test.context.SpringBootTest;
导入org.springframework.http.MediaType;
导入org.springframework.test.context.junit.jupiter.SpringExtension;
导入org.springframework.test.web.servlet.MockMvc;
导入org.springframework.mock.web。
@春靴测试
@ExtendWith(SpringExtension.class)
@AutoConfigureMockMvc
公共类LocaleFilterIntegrationTest{
@自动连线
私有MockMvc;
@试验
public void noLanguageShouldRedirectToSplash()引发异常{
perform(get(“/”).contentType(MediaType.TEXT_HTML)).andExpect(status().isOk());
}
}
我得到了这个错误,正如预期的那样:

java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test.

有很多方法可以加载该过滤器。您可以在过滤器所在的同一个包中(但在
src/test/java
中)创建一个
@SpringBootApplication
伪类,因此应用程序将只扫描有效的包YUP,谢谢@Eugene!