스프링부트

Spring/Spring Boot

Spring REST Docs 설정하기 (build.gradle & .kts)

REST Docs Spring Rest Docs는 Spring MVC를 사용하는 REST API를 문서화할 때 사용하는 툴이다. 다양한 API 문서화 도구 문서툴 노션이나 깃허브 Wiki 등 문서 툴을 사용해 직접 API 문서를 작성하는 방식이다. 서비스 코드의 변경, 작성 실수 등의 이유로 인해 내가 작성한 API 스펙과 실제 코드의 API 스펙이 달라질 수 있다는 문제가 있다. Swagger 대중적인 API 문서화 툴이다. Swagger를 사용해서 API를 문서화하면 아래와 같이 서비스 코드에 Swagger 관련 어노테이션과 코드가 작성되어야 한다. 때문에 코드의 양이 방대해져 서비스 가독성이 떨어뜨릴 수 있는 문제점이 있다. @RestController @RequestMapping("/v1/cate..

Spring/Spring Boot

Spring Boot 환경 QueryDSL 설정 (build.gradle & .kts)

QueryDSL JPA에서 제공하는 객체지향쿼리인 JPQL(Java Persistence Query Language)을 통해 동적 쿼리를 구성하면 코드가 굉장히 난잡해진다는 것을 느낄 수 있다. JPQL은 문자열을 사용한다. 문자열을 조건에 따라 이어붙이는 형식으로 구성하기 때문에 생기는 문제가 있다. 문자열이기에 오타가 발생해도 컴파일 단계에서 에러를 잡아주지 못한다.(다만, NamedQuery를 사용하면 가능하다) 또한 동적쿼리를 구성할 때, 중간중간 if문에 의해 문자열이 추가되기 때문에 가독성이 떨어진다. 따라서 쿼리를 체계적으로 관리하기 어렵다. QueryDSL은 위와 같은 문제를 해결하기 위해 만들어졌다. Type-Safe한 쿼리를 사용하기 위해 엔티티와 매핑되는 정적 타입 QClass를 생성..

JAVA/오류해결

[SpringBoot][오류해결] The dependencies of some of the beans in the application context form a cycle

구글 OAuth를 사용하던 도중 오류가 발생했다. APPLICATION FAILED TO START. 앱이 실행하는 것에 실패했다고 나온다. 오류 내용을 확인해보자. - 오류 내용 *************************** APPLICATION FAILED TO START *************************** Description: The dependencies of some of the beans in the application context form a cycle: ┌─────┐ | securityConfig (field private com.cos.security1.config.oauth.PrincipalOauth2UserService com.cos.security1.confi..

JAVA/오류해결

[Spring Boot][오류해결] Modifying queries can only use void or int/Integer as return type

Resolved [org.springframework.dao.InvalidDataAccessApiUsageException: Modifying queries can only use void or int/Integer as return type! Offending method: public abstract com.example com.example.repository.myRepository.mySave(int,int,java.lang.String); nested exception is java.lang.IllegalArgumentException: Modifying queries can only use void or int/Integer as return type! Offending method: publ..

JAVA/오류해결

[Spring Boot][오류해결] Executing an update/delete query

스프링 부트를 사용할 때 네이티브 쿼리를 통해 JPARepository를 다루는 경우가 있다. 그런데 아래와 같은 오류가 발생할 때가 있다. Resolved [org.springframework.dao.InvalidDataAccessApiUsageException: Executing an update/delete query; nested exception is javax.persistence.TransactionRequiredException: Executing an update/delete query] TransactionRequiredException이 발생한 것인데, update/delete 쿼리를 실행할 때 @Transactional을 붙여주지 않았기 때문에 발생한 에러이다. 문제의 코드 publ..

JAVA/오류해결

[Spring Boot][오류해결] Parameter 0 of constructor in ~~ required a bean of type ~~ that could not be found.

에러상황 *************************** APPLICATION FAILED TO START *************************** Description: Parameter 0 of constructor in com.bigbell.accountbook.rest.AccountRestController required a bean of type 'com.bigbell.accountbook.service.TodayAccountService' that could not be found. Action: Consider defining a bean of type 'com.bigbell.accountbook.service.TodayAccountService' in your configura..

gakko
'스프링부트' 태그의 글 목록