[Error] Initializing Spring DispatcherServlet 'dispatcherServlet', Request method 'GET' not supported, Required request body is missing, Null return value from advice does not match primitive return type

우정·2023년 1월 2일
0

[Error]

목록 보기
2/3
  • 404 에러
INFO 9892 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
INFO 9892 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
INFO 9892 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet        : Completed initialization in 19 ms
  • 해결방법 : Controller 클래스에 @RestController 입력
  • 그랬더니 405 Method Not Allowed
INFO 16736 --- [io-8080-exec-10] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
INFO 16736 --- [io-8080-exec-10] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
INFO 16736 --- [io-8080-exec-10] o.s.web.servlet.DispatcherServlet        : Completed initialization in 7 ms
WARN 16736 --- [io-8080-exec-10] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported]
  • 원인 : 포스트맨에서 GET 방식으로 send 하고 있었음..
  • 해결방법 : POST로 바꾼 후 send
  • 또 다른 에러,,
WARN 16736 --- [nio-8080-exec-7] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public com.project.api.dto.CreateUserResponse com.project.api.controller.UserController.createUser(com.project.api.dto.CreateUserRequest)]
  • 해결 방법 : Controller에서 적었던
    new CreateUserResponse(200L, "회원가입 완료") 빼보기
  • 그래도 안 됨,, 뺀 자리에 new "회원가입완료";로 작성
WARN 13704 --- [nio-8080-exec-2] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public java.lang.String com.project.api.controller.UserController.createUser(com.project.api.dto.CreateUserRequest)]
  • 원인 : 포스트맨 Body에 username이랑 password를 작성 안 했었음!
  • 작성해봄 -> 500 Internal Server Error
ERROR 8760 --- [nio-8080-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.aop.AopInvocationException: Null return value from advice does not match primitive return type for: public abstract boolean com.project.api.repository.UserRepository.findByUsername(java.lang.String)] with root cause
org.springframework.aop.AopInvocationException: Null return value from advice does not match primitive return type for: public abstract boolean com.project.api.repository.UserRepository.findByUsername(java.lang.String)
	a
  • 원인 : UserRepository의 boolean타입때문?
  • UserRepository
boolean findByUsername(String username);

->

Optional<User> findByUsername(String username);
  • UserService
boolean isFind = userRepository.findByUsername(createUserRequest.getUsername());
        if(isFind){
            throw new IllegalArgumentException("중복된 이름입니다.");
        }

->

String username = createUserRequest.getUsername();
        Optional<User> found = userRepository.findByUsername(username);
        if (found.isPresent()) {
            throw new IllegalArgumentException("중복된 이름입니다.");
        }

Optional로 변경해보니 해결,,~

0개의 댓글

관련 채용 정보