java
-
Spring boot. JPA Expecting a SELECT query개발 기록 2023. 9. 20. 14:45
JPA를 사용해 delete 쿼리를 날리던중 "Expecting a SELECT query" 라는 오류 메세지가 등장했다. @Query("delete from AbcKeyword ak " + "where ak.profile.id = :id ") void deleteAllByProfileId(UUID id); JPA는 delete를 수행하기 전에 select를 날리기 때문이다. 디버깅 모드로 끊어서 보면 repostory의 delete를 실행하는 시점에서는 실제로 select가 실행되고 select 결과에 따라서 트랜젝션이 끝날때 delete를 실행한다. @Transactional // 2. delete 실행 public void deleteAbc(...){ abcRepository.delete~~(id)..
-
Spring Boot. How to get custom header value using @RequestHeader개발 기록 2023. 8. 31. 18:58
환경. spring boot 3.1.1 목표. 웹 필터에서 커스텀 헤더를 추가하고 컨트롤러에서 @RequestHeader를 이용해서 값을 가져온다. 시작. 웹 필터에서 커스텀 헤더를 추가하기 위해선 보통 MutableHttpServletRequest를 만들어서 사용할 것이다. 하지만 인터넷에 돌아다니는 보통 많이 쓰는 코드를 가져오면 컨트롤러에서 @RequestHeader를 이용해서 값을 가져오지 못할 것이다. 이유는 getHeaders()를 오버라이딩 하지 않은 코드이기 때문이다. 컨트롤러에서 @RequestHeader를 사용하고 디버깅을 걸어서 코드를 따라가보면 스프링이 getHeaders()에서 값을 가져오는 것을 알 수 있다. (그 중에서도 coyoteRequest라는 변수에서 값을 꺼내온다.) ..
-
Spring Boot. JPA Repository insert multi table under the same Transaction.카테고리 없음 2023. 7. 20. 12:46
공부할 겸 JPA를 한번 사용해 보려고 한다. 환경. java 17 spring boot 3.1.1 목표. 한 트랜젝션에서 여러개의 테이블에 insert나 update 작업이 필요하면 어떡하지? 문제. JPA의 레파지토리를 보면 CrudRepository 인터페이스부터 save()를 제공한다. 이 save 메소드는 SimpleJpaRepository에서 overriding해서 구현되어진다. @Repository @Transactional(readOnly = true) public class SimpleJpaRepository implements JpaRepositoryImplementation { ... @Transactional @Override public S save(S entity) { Asser..
-
MyBatis. BindingException: parameter '~~' not found개발 기록 2023. 5. 31. 14:12
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'userId' not found. Available parameters are [arg1, arg0, param1, param2] MyBatis를 사용하면 Mapper 부분에서 종종 만나는 오류이다. 코드를 수정한 것이 없는데 개발을 하다 보면 갑자기 나오기도 한다. 하나하나 파악해보겠다. 환경: java 1.8 spring boot 원인: (아래의 코드들은 자바 버전에 따라서 개선된 부분이 있지만 큰 틀은 비슷하다.) 오류가 난 부분부터 코드를 따라가다 보면 MapperMethod 클래스의 이너..
-
MSA - Spring Cloud Gateway개발 기록 2023. 4. 21. 14:25
지난 MSA블로그에서 구성 중 유레카 서버와 설정 서버를 만들었다. - (유레카) https://neunggu.tistory.com/16 - (설정서버) https://neunggu.tistory.com/18 이번에는 게이트 웨이를 만들어 유레카와 설정서버를 연결한다. 코드는 깃허브에 있다. (https://github.com/neunggu/msa-gateway) GitHub - neunggu/msa-gateway Contribute to neunggu/msa-gateway development by creating an account on GitHub. github.com 1. build.gradle에 dependency 추가 dependencies { // 설정 서버 implementation 'or..
-
MSA - Spring Cloud Config server개발 기록 2023. 4. 11. 12:05
지난 MSA 블로그에서는 유레카 간단히 유레카 서버를 만들었다. (https://neunggu.tistory.com/16) MSA - Spring Cloud Eureka server 스프링 부트에서는 유레카 서버를 아주 간단히 만들 수 있다. 코드는 깃허브에 있다.(https://github.com/neunggu/msa_eureka) GitHub - neunggu/msa_eureka: eureka server eureka server. Contribute to neunggu/msa_eureka development b neunggu.tistory.com 이번에는 설정 서버를 만들어 유레카에 추가한다. 코드는 깃허브에 있다.(https://github.com/neunggu/msa-config-server)..
-
MSA - Spring Cloud Eureka server개발 기록 2023. 4. 9. 15:12
스프링 부트에서는 유레카 서버를 아주 간단히 만들 수 있다. 코드는 깃허브에 있다.(https://github.com/neunggu/msa-eureka) GitHub - neunggu/msa-eureka: eureka server eureka server. Contribute to neunggu/msa-eureka development by creating an account on GitHub. github.com 1. build.gradle에 dependency 추가 dependencies { implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server' implementation 'org.springframew..
-
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration개발 기록 2023. 3. 27. 16:05
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test 테스트 코드를 실행시키다 만난 오류이다. 원인 @SpringBootApplication 이 붙어있는 메인 클래스와 @SpringBootTest가 붙어있는 테스트 코드의 패키지명이 달라서 생긴 오류였다. (패키지명 수정중이었다.) 해결 패키지명을 일치시킨다.
-
DB 이중화하기 with Spring AOP개발 기록 2023. 3. 19. 15:12
목표 데이터 베이스를 이중화하여 슬레이브에서 select를 하려고 한다. 코드는 github에 있다.(https://github.com/neunggu/score.git) GitHub - neunggu/score Contribute to neunggu/score development by creating an account on GitHub. github.com 환경 java 17 spring boot 2.7.6 spring-boot-starter-aop 사용 방법 1. 마스터, 슬레이브 2개의 DataSource를 생성해 AbstractRoutingDataSource에 담는다. (세션에 접속할 db를 선정해 두고 사용할 예정) (determineCurrentLookupKey 구현 필요) @Configur..
-
Webflux + Jwt(es256)개발 기록 2023. 3. 14. 02:34
웹플럭스 기반의 jwt인증 서버를 구현하며 문제가 됐던 부분 위주의 정리이고, 개인적인 의견이다. 코드는 github에 있다.( https://github.com/neunggu/auth ) GitHub - neunggu/auth: auth server auth server. Contribute to neunggu/auth development by creating an account on GitHub. github.com 1. ReactiveAuthenticationManager를 꼭 구현해야하는가? ** 결론부터 이야기하면 jwt를 구현하는데 있어서 굳이 따 구현할 필요는 없다. 먼저 AbstractUserDetailsReactiveAuthenticationManager에서 authenicate를 구현..