Java/spring16 [스프링 입문] 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. [스프링 입문] ch04 스프링 빈과 의존관계 스프링 빈을 등록하는 2가지 방법 컴포넌트 스캔과 자동 의존관계 설정 자바 코드로 직접 스프링 빈 등록하기 실무에서는 주로 정형화된 컨트롤러, 서비스, 리포지토리 같은 코드는 컴포넌트 스캔을 사용한다. 그리고 정형화 되지 않거나, 상황에 따라 구현 클래스를 변경해야 하면 설정을 통해 스프링 빈으로 등록한다. controller->MemberController.java 생성 package hello.hellospring.controller; import hello.hellospring.service.MemberService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.C.. 2022. 5. 13. [스프링 입문] ch03 회원 관리 예제 - 백엔드 개발 1. 비즈니스 요구사항 정리 데이터: 회원ID, 이름 기능: 회원 등록, 조회 아직 데이터 저장소가 선정되지 않음(가상의 시나리오) 컨트롤러: 웹 MVC의 컨트롤러 역할 서비스: 핵심 비즈니스 로직 구현 리포지토리: 데이터베이스에 접근, 도메인 객체를 DB에 저장하고 관리 도메인: 비즈니스 도메인 객체, 예) 회원, 주문, 쿠폰 등등 주로 데이터베이스에 저장하고 관리됨 아직 데이터 저장소가 선정되지 않아서, 우선 인터페이스로 구현 클래스를 변경할 수 있도록 설계 데이터 저장소는 RDB, NoSQL 등등 다양한 저장소를 고민중인 상황으로 가정 개발을 진행하기 위해서 초기 개발 단계에서는 구현체로 가벼운 메모리 기반의 데이터 저장소 사용 2. 회원 도메인과 리포지토리 만들기 java->hello.hellos.. 2022. 5. 13. [스프링 입문] ch02 웹 개발 기초 (정적 컨텐츠, MVC와 템플릿 엔진, API) 1. 정적 컨텐츠 서버에서 따로 가공을 거치지 않고 파일을 웹 브라우저에 그대로 보내는 방식이다. 1. 스프링은 hello-spring으로 요청이 들어오면 관련 컨트롤러를 찾는다. 2. 없는 경우 정적 컨텐츠를 찾아 그대로 반환해준다. 정적 컨텐츠 입니다. resources->static->hello-static.html 파일을 생성한 후 http://localhost:8070/hello-static.html에서 확인한다. 2. MVC와 템플릿 엔진 Model, View, Controller 1. 웹 브라우저에서 hello-mvc를 넘기면 내장 톰켓 서버를 먼저 거친다. 2. 스프링 컨테이너에서 helloController는 mapping이 되있는 것을 확인하고 그 메서드를 호출한다. 3. Model 객.. 2022. 5. 12. [스프링 입문] ch01 프로젝트 환경설정 CH01 프로젝트 환경설정 1. JAVA 11 설치 https://www.oracle.com/java/technologies/downloads/ 2. IDE: IntelliJ 설치 https://www.jetbrains.com/idea/ 3. 스프링 프로젝트 생성 https://start.spring.io/ gradle project, java, 가장 최신 버전, java 11으로 설정한다. add dependencies에 spring web과 thymeleaf를 추가한다. generate 버튼을 누르고 파일을 다운로드한다. Intelli J에서 build.gradle 파일을 열어준다. Windows: Settings(Ctrl+Alt+S)->gradle 빨간색 박스의 Build and run using를.. 2022. 5. 10. 이전 1 2 다음