안녕하세요 강사님. ObjectMapper가 @Autowired 못읽어오는데 어디서 잘못된건지 모르겠습니다.
1641
작성한 질문수 47
안녕하세요. 강의 매우 잘 듣고 있습니다 !
다름이 아니라 @WebMvcTest 을 빼고 @AutoConfigureMockMvc 를 사용했을 떄,
@Autowired ObjectMapper objectMapper;
이 쪽에서 에러가 발생하는데 어디쪽을 보면 될까요..?
Could not autowire. No beans of 'ObjectMapper' type found.
감사합니다.
답변 1
2
안녕하세요.
@SpringBootTest는 추가하셨나요?
@WebMvcTest를 안쓰실꺼라면 @SpringBootTest와 @AutoConfigureMockMvc를 조합해서 쓰셔야 합니다.
감사합니다.
0
안녕하세요.
네 맞습니다. 조합해서 사용했는데 에러가 발생하네요.
그래서 스택 오버플로우 보는데
https://stackoverflow.com/questions/30060006/how-do-i-obtain-the-jackson-objectmapper-in-use-by-spring-4-1
이거 참고하라고 해서 이런식으로 했는데도,
Could not autowire. No beans of 'Jackson2ObjectMapperBuilder' type found.
이렇게 에러가 발생하네요.
감사합니다.
// 처음 코드
@SpringBootTest
@ExtendWith(SpringExtension.class)
@AutoConfigureMockMvc
class EventControllerTest {
@Autowired MockMvc mockMvc;
@Autowired ObjectMapper objectMapper;
@Test
void createEVent() throws Exception {
Event event = Event.builder()
.id(100)
.name("Spring")
.description("REST API Development with Spring")
.beginEventDateTime(LocalDateTime.of(2021, 10, 30, 12, 00))
.closeEnrollmentDateTime(LocalDateTime.of(2021, 10, 31, 12, 00))
.beginEnrollmentDateTime(LocalDateTime.of(2021, 11, 01, 12, 00))
.endEventDateTime(LocalDateTime.of(2021, 11, 02, 12, 00))
.basePrice(100)
.maxPrice(200)
.limitOfEnrollment(100)
.location("강남역")
.free(true)
.offline(false)
.build();
mockMvc.perform(post("/api/event")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaTypes.HAL_JSON)
.content(objectMapper.writeValueAsString(event)))
.andDo(print())
.andExpect(status().isCreated())
.andExpect(jsonPath("id").exists())
.andExpect(header().exists(HttpHeaders.LOCATION))
.andExpect(header().string(HttpHeaders.CONTENT_TYPE, MediaTypes.HAL_JSON_VALUE))
.andExpect(jsonPath("id").value(Matchers.not(100)))
.andExpect(jsonPath("free").value(Matchers.not(true)));
}
}
// stackoverflow 수정 코드
@Autowired Jackson2ObjectMapperBuilder builder;
@Test
void createEVent() throws Exception {
ObjectMapper objectMapper = builder.build();
Spring 시큐리티 관련해서 WebSecurityConfigurationAdapter
0
84
1
junit5 사용하시는 분들
0
99
1
자바 빈 스펙을 준수하는지 체크하는 테스트
0
255
2
REST API 개발 중 비즈니스 로직 적용 부분의 JSON 에러
0
257
1
스프링 부트 3버전에서의 실습
0
196
1
java.lang.AssertionError: Status
0
541
2
spring doc 관련 파일 생성 관련 배포 관련 질문 드립니다.
0
292
1
섹션2 201응답받기 부분 테스트 404에러 질문입니다
0
744
1
강의 자료가 404입니다 확인 부탁 드려요!
0
482
1
연동 DB문의
0
368
1
이벤트 Repository강의 중 Event 클래스에 private Integer Id; 위치 질문
0
509
1
(Mac) postgressql 관련하여 port kill 해도 다시 살아나는 경우
0
387
0
maven으로 생성한 docs파일(index.html)에서의 not found 오류 질문
0
636
1
테스트 오류 질문드립니다.
0
518
1
docs 요청값이 반영이 안되네요... (해결)
-1
399
1
psql 적용 후 에러
0
825
2
mvn package 시 다음과 같은 에러가 나시면
0
770
2
Event에 Account manager를 추가했으면 문서화 필요
0
277
1
2년 훨씬 전 부터 Restlet-> Talend API 로 바뀌었습니다~
1
475
1
asciidoc 추가 스니펫 에러 해결법
0
403
1
_links 는 현재 fieldWithPath 를 해주지 않아도 됩니다.
0
431
3
깃랩 처음 사용자를 위한 index.adoc raw 보는 법
0
338
1
eclipse 쓰시는 분을 위한 maven-resources-plugin 팁
0
342
1
부트 + jupiter 인 경우 설정법
0
346
1





