본문 바로가기

전체 글31

[회원 관리 예제 : 웹 MVC 개발] 홈, 회원 등록, 회원 조회 본격적으로 url 요청에 따른 Controller 들을 설정해주도록 하자. 홈 화면 추가 localhost:8080 요청 시, 홈 화면(home.html)으로 이동한다. 기존에 똑같은 매핑이 resource > static 에 index.html 로 존재했으나, @Controller 에서 Spring Container 가 먼저 매핑되는 화면을 먼저 찾기 때문에 home.html 이 우선적으로 보여진다. 회원 등록 form 태그에서 post로 "/members/new" 로 넘기고 해당 처리 메소드 create의 인자로 MemberForm 타입이 들어간다. createMemberForm에서 form 태그로 넘어온 input의 name key의 input value "spring" 을 MemberForm 의 .. 2022. 7. 1.
[Spring Bean과 의존관계 - (2)] Java Code 로 직접 Spring Bean 에 등록하기 기존에 Component Scan 방식이 아닌 직접 자바 코드를 이용해서 Bean 에 등록할 것이기 때문에, Controller를 제외한 @Service, @Repository, @Autowired 를 제거한다. SpringConfig Main method Scope 에 SpringConfig class 를 생성하고, 다음과 같이 작성한다. Spring 이 @Configuration 으로 인식하면, @Bean annotation으로 등록한 MemberService 와 MemberRepository 를 Bean 으로 등록한다. MemberService 에서 MemberRepository 가 Bean 으로 등록되어 있는지 Spring container 내에서 객체를 찾고, 위에서 @Bean 으로 등록했기 때.. 2022. 7. 1.
[Spring Bean과 의존관계 - (1)] Component Scan 과 자동 의존관계 설정 간단히말해, 기존에 작성한 Service 와 Repository, Controller 를 @Service, @Repository, @Controller 어노테이션을 이용하여 Spring Container 가 자동으로 Bean 에 등록하고, 의존관계를 설정할 수 있도록 한다. Spring Bean 을 등록하는 방법에는 두 가지가 있다. Component Scan 으로 자동 의존관계 설정 - @Component : @Controller, @Service, @Repository 자바 코드로 직접 Spring Bean 에 등록 이번에 알아볼 방법은 1번이다. controller > MemberController 생성 **@Controller 를 설정했을 때 벌어지는 일 한마디로 Spring container에서.. 2022. 7. 1.
[회원 관리 예제, 백엔드 개발 - (5)] 회원 서비스 테스트 git repository : https://github.com/Rezalog/spring-boot-entry-inf GitHub - Rezalog/spring-boot-entry-inf Contribute to Rezalog/spring-boot-entry-inf development by creating an account on GitHub. github.com 구현한 회원 서비스, MemberService 를 테스트하기 위한 코드를 작성해보자. 이때 테스트 코드 작성시, given-when-then 으로 나누어 작성하는 습관을 들이자! (**cmd + shift + T 로 테스트 자동 생성이 가능 !) MemberServiceTest beforeEach MemoryMemberRepository 은 .. 2022. 6. 30.
[회원 관리 예제, 백엔드 개발 - (4)] 회원 서비스 개발 git repository : https://github.com/Rezalog/spring-boot-entry-inf GitHub - Rezalog/spring-boot-entry-inf Contribute to Rezalog/spring-boot-entry-inf development by creating an account on GitHub. github.com 회원 서비스 : 회원 리포지토리와 도메인을 활용해서, 실제 비즈니스 로직을 구현한다. 실제로 구현해볼 서비스는 회원가입, 전체 회원 조회이다. MemberService class join(회원가입) - 기본 로직 도메인인 Member 타입으로 받은 회원정보로 중복 회원을 검증하고, repo에 저장한 뒤 Long type 의 id를 반환한다. .. 2022. 6. 30.
[회원 관리 예제, 백엔드 개발 - (3)] 회원 리포지토리 테스트 케이스 작성 git repository : https://github.com/Rezalog/spring-boot-entry-inf GitHub - Rezalog/spring-boot-entry-inf Contribute to Rezalog/spring-boot-entry-inf development by creating an account on GitHub. github.com 메인 메소드나 Controller를 실행해서 테스트를 하기에는 준비 및 실행이 오래걸리고, 반복적으로 실행하거나 여러 테스트케이스를 한번에 실행하기 어려운 단점이 있다. 이를 해결하기 위하여 JUnit 을 이용한 테스트 케이스를 작성하고 테스트 해볼 수 있다. JUnit Test 과정 (1) - findById 구현한 interface 인 M.. 2022. 6. 29.