분류 전체보기 97

AppConfig 리팩터링

1) AppConfig 리팩터링 설명 현재 AppConfig를 보면 "중복"이 있고, "역할"에 따른 "구현"이 잘 안 보인다. 한눈에 보일 수 있도록 수정해 보자.! 2) AppConfig 코드 리팩터링 package hello.core; import hello.core.discout.DiscountPolicy; import hello.core.discout.RateDiscountPolicy; import hello.core.member.MemberRepository; import hello.core.member.MemberService; import hello.core.member.MemberServiceImpl; import hello.core.member.MemoryMemberRepository;..

스프링 핵심 원리 이해 - 예제 만들

비즈니스 요구사항과 설계 1) 회원 회원을 가입하고 조회할 수 있다. 회원은 일반과 VIP 두 가지 등급이 있다 회원 데이터는 자체 DB를 구축할 수 있고, 외부 시스템과 연동할 수 있다. (미확정) 2) 주문과 할인 정책 회원은 상품을 주문 할 수 있다. 회원 등급에 따라 할인 정책을 적용할 수 있다. 할인 정책은 모든 VIP는 1000원을 할인해주는 고정 금액 할인을 적용해달라. 할인 정책은 변경 가능성이 높다. 회사의 기본 할인 정책을 아직 정하지 못했고, 오픈 직전까지 고민을 미루고 싶다. 최악의 경우 할인을 적용하지 않을 수 도 있다. (미확정) 소스코드는 아래 확인 가능 https://github.com/qkrxodud/spring_basic GitHub - qkrxodud/spring_bas..

스프링 핵심 원리 - 기본편 - 객체 지향 설계와 스프링

스프링의 진짜 핵심 스프링은 자바 언어 기반의 프레임 워크이다. 자바 언어의 가증 큰 특징 - 객체 지향 언어 스프링은 좋은 객체 지향 애프리케이션을 개발할 수 있게 도와주는 프레임워크 다형성의 실세계 비유 운전자는 자동차가 변경이 되도, 운전이 가능하다. 운전자는 자동차 인터페이스 즉 역할만 알 뿐, 구조는 몰라도 된다. -> 클라이언트에 영향을 주지 않고 새로운 기능을 제공하며, 무한하게 확장 할 수 있다. 로미오 역할은 장동건이 해도되고 원빈이 해도된다. 로미오 역할은 줄리엣 역할을 누가 하는지 몰라도 된다. -> 변경이 유연하고 자유롭다. 역할과 구현을 분리 역할과 구현으로 구분하면 세상이 다순해지고, 유연해지며 변경도 편리해진다. 장점 클라이언트는 대상의 역할(인터페이스)만 알면 된다. 클라이언..

AOP가 필요한 상황, 사용법

1) 상황 발생 '각각의 함수의 측정 시간을 알고 싶다' 요청 우리는 여기서 핵심 프로세서와 공통 관심사항 2개로 나눠지게 된다. 함수 측정 + 프로세서 로직으로 아래 예시를 보자. package hello.hellospring.service; import hello.hellospring.domain.Member; import hello.hellospring.repository.MemberRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util..

스프링 데이터 JPA & 통합 테스트

스프링 데이터 JPA를 사용하면 리포지토리에 구현 클래스 없이 인터페이스 만으로 개발을 완료할 수 있다. 사용법을 알아보자. 1) SrpingDataJpaMemberRepostiory 인터페이스를 생성 SrpingDataJpaMemberRepostiory 인터페이스에 extends JapRepository , MemberRepostiory로 상속받는다. 상속을 받게되면 Spring Jpa가 JpaRepostiory를 상속받는 클래스의 구현체를 자동으로 만들어주고, 만들어진 구현체를 토대로 스프링 빈에 자동으로 등록을 해준다. 우리는 이제 SpringConfig에서 등록된 MemberRepository를 사용하면 된다. package hello.hellospring.repository; import hel..

스프링 JPA & 통합 테스트

JPA를 사용하면, SQL과 데이터 중심의 설계에서 객체 중심의 설계로 패러다임을 전환을 할 수 있다. JPA를 사용하면 개발 생산성을 크게 높일 수 있다. 1) build.gradle을 통한 외부라이브러리 임포트 기존에 사용했던 jdbc를 주석 처리후 data-jpa를 작성해준다. dependencies { implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-web' //implementation 'org.springframework.boot:spring-boot-starter-jdbc' implementation 'o..

스프링 JDBCTemplate & 통합 테스트

스프링 JdbcTemplate으로 구현해보자. 1) JdbcTemplate JdbcTemplate은 Template Method 패턴을 사용해서 이름이 작명되었다. 부연설명 : Template Method pattern은 추상 클래스에 공통되는 Process를 작성한 후 구현 클래스에서 부모 클래스에서 사용되는 함수들을 만들면 부모 클래스의 프로세스를 중심으로 해당하는 기능들을 만드는 것이다. url : https://github.com/qkrxodud/object_pratice/tree/main/lib/TemplateMethodPatten GitHub - qkrxodud/object_pratice Contribute to qkrxodud/object_pratice development by creati..

스프링 통합 테스트

지금까지의 기능들을 테스트해보자! test > java > hello.hellospring > service > MemberServiceIntegration.java를 생성 @SpringBootTest : Spring부팅을 시작해 준다. @Transactional : DB(데이터 베이스) 테스트 중 insert, update, delete 되는 기능을 확인 후에 롤백시켜준다. 테스트를 지속적으로 할 수 있게 유지시켜준다. package hello.hellospring.service; import hello.hellospring.domain.Member; import hello.hellospring.repository.MemberRepository; import org.assertj.core.api.Ass..

순수 JDBC 사용 및 연동

1) JDBC 연동 Jdbc를 연동하기 위해서는 예전 시간에 만들어 놓았던 SrpingConfig.java 파일이 필요하다. DataSource는 spring이 application.properties의 환경설정 값을 토대로 스프링 컨테이너에 빈으로 등록하기 때문에 아래와 같이 Autowired로 DI의존성 주입을 받을 수 있다. package hello.hellospring; import hello.hellospring.repository.MemoryMemberRepository; import hello.hellospring.service.MemberService; import org.springframework.beans.factory.annotation.Autowired; import org.spr..

h2 데이터베이스 설치 및 연동

h2 데이터를 설치하고 Spring에 연결하자. 다운로드 url : https://www.h2database.com/html/download-archive.html Archive Downloads www.h2database.com 1) version : 1.4.200 을 설치 2) 설치 파일을 압축을 풀은 후 h2.bat 파일을 실행 3) JDBC url을 프로토콜로 연결하자. 4) 멤버 테이블 생성 CREATE TABLE member( id bigint generated by default as identity, name VARCHAR(255), primary key (id) ); 5) Spring H2 DataBase 연동 build.gradle의 dependencies에 implementation을..