나는 다음과 같이 내 주요 봄 부팅 응용 프로그램 클래스에 Jackson2ObjectMapperBuilder
을 사용자 정의사용자 정의 Jackson2ObjectMapperBuilder는 통합 springboot 시험에서 인식되지
모든. ExampleFilter
은 SimpleBeanPropertyFilter
의 확장
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Autowired
public void configureJackson(Jackson2ObjectMapperBuilder builder) {
builder.filters(new SimpleFilterProvider().addFilter("customFilter", new ExampleFilter()));
}
. 내 POJO에는 Jackson의 @JsonFilter("customFilter")
주석이 달려 있습니다. @RestController
및 @GetMapping
주석을 사용하여 HTTP를 통해 POJO를 노출했습니다. 잘 작동하고 응용 프로그램을 실행하고 끝점에 액세스 할 때 사용자 지정 필터가 호출됩니다.
이제 통합 테스트가 아래와 같이 작성되었습니다.
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class IntegrationTest {
@LocalServerPort
private int port;
@Autowired
private TestRestTemplate restTemplate;
@Test
public void getUser() throws Exception {
POJO obj = this.restTemplate.getForObject("http://localhost:" + this.port + "/pojo", POJO.class);
Assertions.assertThat(obj).isNotNull();
Assertions.assertThat(obj.getFirstName()).isEqualTo("Jane");
Assertions.assertThat(obj.getLastName()).isEqualTo("Doe");
Assertions.assertThat(obj.getAge()).isEqualTo("24");
}
}
내가 테스트를 실행하는 경우, obj가 null로 와서 내가 no FilterProvider configured
Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: Can not resolve PropertyFilter with id 'customFilter'; no FilterProvider configured; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not resolve PropertyFilter with id 'customFilter'; no FilterProvider configured
내가 무슨 일을하고 오전 오류를보고 나는이 문제를 어떻게 해결합니까?
내 폴더 구조이다
SRC/주/자바/COM/A/B/C/Application.java
SRC/주/자바/COM/A/B/C/제어기/ControllerA.java
SRC/테스트/자바/COM/A/B/C/컨트롤러/IntegrationTest.java