스프링10 [스프링 기본] ch01 객체 지향 설계와 스프링-SOLID 원칙 SOLID : 클린코드로 유명한 로버트 마틴이 좋은 객체 지향 설계의 5가지 원칙을 정리 1. SRP : 단일 책임 원칙 (single responsibility principle) 모든 클래스는 하나의 책임만 가지며, 클래스는 그 책임을 완전히 캡슐화해야 함 변경이 있을 때 파급 효과가 적으면 잘 따른 것 2. OCP : 개방-폐쇄 원칙 (open/closed principle) 가장 중요한 원칙 소프트웨어 요소는 확장에 열려있고 변경에 닫혀 있는 것 다형성 활용 인터페이스를 구현한 새로운 클래스를 하나 만들어서 새로운 기능 구현 문제점 : 구현 객체를 변경하려면 클라이언트 코드를 변경해야 함->ocp원칙이 깨짐->객체를 생성하고, 연관관계를 맺어주는 별도의 조립, 설정자가 필요함 3. LSP 리스코프.. 2022. 5. 26. [스프링 기본] ch01 객체 지향 설계와 스프링-스프링이란? 1. 스프링의 역사 초기의 기업들은 자바의 표준 기술로 Enterprise Java Bean을 사용했다. Rod Johnson은 EJB 없이도 충분히 고품질의 확장 가능한 애플리케이션을 개발할 수 있음을 보여주고, 30,000라인 이상의 기반 기술을 예제 코드로 선보이며 EJB의 문제점을 지적하는 책을 출간했다. BeanFactory, ApplicationContext, POJO, 제 어의 역전, 의존관계 주입 등 지금의 스프링 핵심 개념과 기반 코드가 들어가 있다. 출간 직후 Juergen Hoeller, Yann Caroff가 로드 존슨에게 오픈소스 프로젝트를 제안하였다. 스프링 이름은 전통적인 J2EE(EJB)라는 겨울을 넘어 새로운 시작이라는 뜻으로 지어졌다. 2. 스프링 프레임워크 핵심 기술: .. 2022. 5. 25. [스프링 입문] ch07 AOP 1. AOP가 필요한 상황 모든 메소드의 호출 시간을 측정하고 싶다면? 공통 관심 사항(cross-cutting concern) vs 핵심 관심 사항(core concern) 회원 가입 시간, 회원 조회 시간을 측정하고 싶다면? MemberService.java package hello.hellospring.service; import hello.hellospring.domain.Member; import hello.hellospring.repository.MemberRepository; import hello.hellospring.repository.MemoryMemberRepository; import org.springframework.beans.factory.annotation.Autowired;.. 2022. 5. 23. [스프링 입문] ch06 스프링 DB 접근 기술-스프링 데이터 JPA 6. 스프링 데이터 JPA 스프링 데이터 JPA는 JPA를 편리하게 사용하도록 도와주는 기술이다. 스프링 부트와 JPA만 사용해도 개발 생산성이 많이 증가하고, 개발해야할 코드도 확연히 줄어든다. 여기에 스프링 데이터 JPA를 사용하면, 리포지토리에 구현 클래스 없이 인터페이스 만으로 개발을 완료할 수 있습니다. 그리고 반복 개발해온 기본 CRUD 기능도 스프링 데이터 JPA가 모두 제공합니다. 따라서 개발자는 핵심 비즈니스 로직을 개발하는데, 집중할 수 있습니다. 앞의 JPA 설정을 그대로 사용한다. repository/SpringDataJpaMemberRepository 인터페이스 생성 package hello.hellospring.repository; import hello.hellospring.d.. 2022. 5. 19. [스프링 입문] ch06 스프링 DB 접근 기술-JPA 5. JPA JPA는 기존의 반복 코드는 물론이고, 기본적인 SQL도 JPA가 직접 만들어서 실행해준다. JPA를 사용하면, SQL과 데이터 중심의 설계에서 객체 중심의 설계로 패러다임을 전환을 할 수 있다. 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 'org.springfram.. 2022. 5. 19. [스프링 입문] ch06 스프링 DB 접근 기술-스프링 JdbcTemplate 4. 스프링 JdbcTemplate 순수 Jdbc와 동일한 환경설정을 하면 된다. implementation 'org.springframework.boot:spring-boot-starter-jdbc' runtimeOnly 'com.h2database:h2' 스프링 JdbcTemplate과 MyBatis 같은 라이브러리는 JDBC API에서 본 반복 코드를 대부분 제거해준다. 하지만 SQL은 직접 작성해야 한다. repository/JdbcTemplateMemberRepository.java 생성 package hello.hellospring.repository; import hello.hellospring.domain.Member; import org.springframework.beans.factor.. 2022. 5. 19. [스프링 입문] ch06 스프링 DB 접근 기술-스프링 통합 테스트 3. 스프링 통합 테스트 스프링 컨테이너와 DB까지 연결한 통합 테스트를 진행해봅시다. 우선 DB에 있는 member를 지워줍니다. delete from member service/MemberServiceIntegrationTest.java 생성 package hello.hellospring.service; import hello.hellospring.domain.Member; import hello.hellospring.repository.MemberRepository; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.t.. 2022. 5. 19. [스프링 입문] ch06 스프링 DB 접근 기술-H2 데이터베이스 설치, 순수 JDBC 1. H2 데이터베이스 설치 > h2 데이터베이스는 꼭 다음 링크에 들어가서 1.4.200 버전을 설치해주세요. > 최근에 나온 2.0.206 버전을 설치하면 일부 기능이 정상 동작하지 않습니다. https://www.h2database.com/html/download-archive.html Archive Downloads www.h2database.com h2.bat 실행 (windows 배치 파일) 데이터베이스 파일 생성 방법 jdbc:h2:~/test (최초 한번) ~/test.mv.db 파일 생성 확인 이후부터는 jdbc:h2:tcp://localhost/~/test 이렇게 접속 H2 데이터베이스에 접근해서 member 테이블 생성 drop table if exists member CASCADE;.. 2022. 5. 19. [스프링 입문] ch05 회원 관리 예제 - 웹 MVC 개발 1. 회원 웹 기능 - 홈 화면 추가 controller->HomeController.java 생성 package hello.hellospring.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @Controller public class HomeController { @GetMapping("/") public String home() { return "home"; } } resources->templates->home.html 생성 Hello Spring 회원 기능 회원 가입 회원 목록 MVC와 템플릿에서 배운 내용과 같이 내장 톰켓 서.. 2022. 5. 17. 이전 1 2 다음