Back-End

    스프링 WebClient로 graphql 서버에 요청응답받기

    org.springframework.boot spring-boot-starter-webflux 3.0.2 com.graphql-java-kickstart graphql-webclient-spring-boot-starter 1.0.0 WebClient 가 webflux에 포함되어 있습니다. WebClient webClient = WebClient .builder() .baseUrl("https://apijosu.com/graphql") .defaultHeader("Authorization", "Bearer user token") .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) .build(); WebClient로 get,..

    스프링 Oauth2 Server jdbc 이용한 토큰 Access 토큰 로그인 마다 새롭게 발급 받기 (커스텀)

    토큰이 만료되었는지 체크해서 발급해주는 서비스인 TokenServices DefaultTokenServices를 상속받아서 CustomTokenServices 를 만들어줍니다. createAccessToken() 이 엑세스 토큰을 만들어 발급해주는 부분입니다. 기존 코드에는 isExpired()를 체크해서 만료되면 재발급해주는 방식입니다. 이 부분을 체크하지 않고 항상 새로 발급하도록 수정해주면 로그인 마다 매번 새로 발급되게 됩니다. package com.coupang.admin.server.coupang_admin_server.common.config; import org.springframework.security.core.AuthenticationException; import org.spring..

    스프링 시큐리티 Oauth2 커스텀 Exception 만들기

    @EnableAuthorizationServer public class OAuthConfig extends AuthorizationServerConfigurerAdapter { @Override public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { endpoints. /* 다른 설정 부분 생략 */ .exceptionTranslator(authorizationWebResponseExceptionTranslator()); } public WebResponseExceptionTranslator authorizationWebResponseExceptionTranslator() { return new D..

    Spring 페이징 처리 중 MyBatis 에러

    //컨트롤러 List userList = userService.findAllPaging(startIndex, page); ...// 서비스 , 레포지토리 ... //매퍼 @Select("SELECT * FROM user limit #{startIndex}, #{pageSize}") List selectPaging(int startIndex, int pageSize); DB는 MySQL을 사용하여 limit 을 통해 0, 5 로 5개의 row만 가져오고 싶었다. 실행을 해보니 nested exception is org.apache.ibatis.binding.BindingException: Parameter 'startIndex' not found. Available parameters are [arg1, ..

    @ControllerAdvice으로 @ExceptionHandler 전역 에러 핸들러 만들기

    @ControllerAdvice @RestControllerAdvice 를 사용하여 @ExceptionHandler 을 전역으로 설정 컨트롤러에서 사용되는 공통 기능들을 모듈화하기 위한 어노테이션으로, @InitBinder @ModelAttribute @ExceptionHandler 세 가지 어노테이션을 지원합니다. 이 중 @ExceptionHandler 를 사용해 보았습니다. @Slf4j @RestControllerAdvice public class ExceptionHandlerAdvice { /* 400 Bad Request - 클라이언트가 유효하지 않은 요청을 보낸 경우 401 Unauthorized - 해당 서버에 클라이언트 인증이 실패한 경우 403 Forbidden - 클라이언트가 인증은 됐지..

    REST API LocalDateTime 사용할 때 문제점 해결해보기

    발생한 문제 생긴 문제는 MyBatis를 사용하여 Json 데이터를 insert하고 user 객체를 반환합니다. 이 때, id는 기본키이며, auto increment이고 det는 datetime, Current_timestamp로 현재 날짜와 시간을 자동으로 생성해줍니다. User class //User @Data public class User{ private long id; private String email; private String password; private String name; private LocalDateTime det; } User Controller //컨트롤러 @PostMapping public Object postUser(@RequestBody @Validated User..

    스프링부트 Mybatis boot-starter로 Mysql 연동하기

    1. xml를 사용하지 않고 mybatis-spring-boot-starter를 사용하여 연동해보겠습니다. https://github.com/mybatis/spring-boot-starter/wiki/Quick-Start mybatis/spring-boot-starter MyBatis integration with Spring Boot. Contribute to mybatis/spring-boot-starter development by creating an account on GitHub. github.com 빠른 시작 방법을 알 수 있습니다. implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.2.0' runtimeOnly 'm..