![[Spring] 스프링 컨테이너(IoC, DI 컨테이너)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbKs3H1%2FbtsM46zw4cc%2Fq2SAe2XuKijZ8Ou4nTOlik%2Fimg.png)
이 글은 인프런 김영한님의 Spring 강의를 바탕으로 개인적인 정리를 위해 작성한 글입니다.SRP (Single Responsibility Principle) :하나의 클래스는 오직 하나의 책임만 가져야 한다.OCP (Open/Closed Principle) :소프트웨어 요소는 확장에는 열려 있고, 변경에는 닫혀 있어야 한다.LSP (Liskov Substitution Principle) :자식 클래스는 부모 클래스의 기능을 대체할 수 있어야 한다.ISP (Interface Segregation Principle) :특정 클라이언트를 위한 인터페이스 여러 개가 범용 인터페이스 하나보다 낫다.DIP (Dependency Inversion Principle) :구체화가 아닌 추상화에 의존해야 한다. OCP..
주요 메서드 정리JUnit 주요 메서드 (org.junit.jupiter.api.Assertions) 메서드 설명 예시 assertEquals(expected, actual) 값이 같은지 비교 assertEquals(10, sum) assertNotEquals(expected, actual) 값이 다르면 통과 assertNotEquals(0, result) assertTrue(condition) 조건이 true면 통과 assertTrue(value > 0) assertFalse(condition) 조건이 f..
@Test의미: 이 메서드는 테스트 메서드임을 명시한다.위치: 테스트 메서드 위@Testvoid 회원가입_성공() { // given // when // then} @BeforeEach의미: 각 테스트 메서드 실행 직전마다 실행된다.주 용도: 공통 초기화, 테스트 상태 정리@BeforeEachpublic void beforeEach() { memberRepository = new MemoryMemberRepository(); memberService = new MemberService(memberRepository); } @AfterEach의미: 각 테스트 메서드 실행 직후마다 실행된다.주 용도: 리소스 정리, 로그 기록 등@AfterEachpublic void afterEac..
![[Spring] Spring Boot + Swagger](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FAVgW8%2FbtsM0pk8piI%2FjGOeFXYhHRz235viW4L4xK%2Fimg.png)
GitHub 저장소: https://github.com/springdoc/springdoc-openapi최신 릴리즈: https://github.com/springdoc/springdoc-openapi/releasesMaven Central: https://search.maven.org/search?q=g:org.springdoc SwaggerSwagger는 RESTful API를 설계, 문서화, 테스트할 수 있도록 도와주는 오픈소스 툴 세트이다.현재는 OpenAPI Specification(OAS)이라는 이름으로 공식적으로 관리되며, 그 구현체 중 하나가 Swagger이다.Swagger는 API의 명세(Specification)를 기계가 읽을 수 있는 형식(JSON 또는 YAML)으로 작성하고,이를 바..
![[Spring] Parameter 0 of constructor in xxx required a bean of type 'xxx' that could not be found.](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbcQEph%2FbtsMYqQ4TLu%2FXhdPvK2Iwa6h6IKUTkfGu1%2Fimg.png)
문제 상황1년전에 만들고 쳐다도 안본 프로젝트를 리팩토링하려고 베이스 패키지를 수정하다가 Parameter 0 of constructor in com.seungwook.r2r.service.IngredientService required a bean of type 'com.seungwook.r2r.repository.IngredientRepository' that could not be found. 이 오류를 만나게 되었다.기존 패키지 구조는 com.receipt2recipe 에서 com.seungwook.r2r로 바꾸었더니 "IngredientService는 IngredientRepository가 필요한데 못찾겠다." 라고 오류를 뿜고있었고, IngredientRepository는 분명히 존재하고 패키..
![[Spring] GeoIP를 이용한 해외 IP 차단](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FstShJ%2FbtsLO6109qd%2F5ZvcbygO69oocyi0UFzNvK%2Fimg.png)
MaxMind 에서 데이터베이스 다운로드MaxMind에서 먼저 데이터베이스를 받아와야한다.국가를 제외한 나머지 자료(시, 도 등)는 꽤 부정확하다는 글이 많고, 해외인지 아닌지가 가장 중요하기 때문에 country 데이터베이스만 사용하기로 했다.아래 사이트에서 회원 가입을 한 후 country 데이터베이스를 다운로드 받는다.(GeoLite2-Country.mmdb)https://www.maxmind.com/en/home 스프링에 적용의존성 추가build.gradle에 geoip 의존성을 추가해준다.implementation "com.maxmind.geoip2:geoip2:4.1.0" 서비스 로직 작성아래 서비스 계층에는getClientIP() : request 객체를 바탕으로 IP를 추출하는 메서드 ge..
개발 환경SpringBoot 3.3.5Java 17PostgreSQL 14 문제 상황ERROR: column "XXX" is of type XXX but expression is of type character varying Hint: You will need to rewrite or cast the expression. @Enumerated(EnumType.STRING)@Column(nullable = false, name = "level")private UserLevel level; 엔티티에 ENUM 타입이 있는데 이를 enum이 아닌 문자열로 인식해서 발생하는 문제임을 알았다.XXX(예시) 라는 컬럼이 있는데, PostgreSQL에서는 ENUM으로 만들었지만, JPA에서 이를 문자열로 인식한 상..
![[Query DSL] Spring Data JPA와 Query DSL 통합(+ Query DSL 페이징 최적화)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fbxp7fz%2FbtsI6ff44JB%2Fbs6ZWNE5VaSxIwTeUUKeD1%2Fimg.png)
이 글은 인프런 김영한님의 Spring 강의를 바탕으로 개인적인 정리를 위해 작성한 글입니다.Query DSL을 Spring Data JPA에서 사용하려면 사용자 정의 리포지토리를 만들어야 한다. MemberTeamDto@Datapublic class MemberTeamDto { private Long memberId; private String username; private int age; private Long teamId; private String teamName; @QueryProjection public MemberTeamDto(Long memberId, String username, int age, Long teamId, String teamName) ..