본문 바로가기

자바54

[자바/스프링] 스프링 통합테스트 스프링 DB 접근 기술 스프링 통합 테스트 스프링 컨테이너와 DB까지 연결한 통합 테스트를 진행해보자. 💾 test > hello > hellospring > service > MemberServiceIntegrationTest package hello.hellospring.service; import hello.hellospring.domain.Member; import hello.hellospring.repository.MemberRepository; import hello.hellospring.repository.MemoryMemberRepository; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; .. 2023. 2. 25.
[자바/스프링] 순수 JDBC 스프링 DB 접근 기술 순수 JDBC 🔎 환경 설정 👉 build.gradle 파일에 jdbc, h2 데이터베이스 관련 라이브러리 추가 ``` implementaion 'org.springframework.boot:spring-boot-starter-jdbc' runtimeOnly 'com.h2database:h2' ``` 💾 build.gradle 👉 스프링 부트 데이터베이스 연결 설정 추가 `resources/application.properties` ``` spring.datasource.url=jdbc:h2:tcp://localhost/~/test spring.datasource.driver-class-name=org.h2.Driver ``` 💾 resources > application.prop.. 2023. 2. 24.
[자바/스프링] H2 데이터베이스 설치 스프링 DB 접근 기술 H2 데이터베이스 설치 순수 JDBC 자바에서 데이터베이스에 접속할 수 있도록 하는 자바 API임 데이터베이스에서 자료를 쿼리하거나 업데이트하는 방법을 제공함 스프링 통합 테스트 스프링 JdbcTemplate JPA 이 기술을 쓰면 객체를 바로 db에 쿼리없이 저장하고 관리할 수 있음 스프링만큼 오래된 기술 스프링 데이터 JPA H2 데이터베이스 설치 이전 시간에 인텔리제이에서 작업했던 거는 메모리에 저장을 해서, 서버가 내려가면 회원 데이터가 모두 사라짐. 당연히 그렇게 되면 안 됨. 그래서 실무에서는 데이터베이스에 데이터들을 저장하고 관리함. 심플하고 간단한 H2 데이터베이스를 설치하기로 함. https://www.h2database.com/html/download-archiv.. 2023. 2. 23.
[자바/스프링] 자바 코드로 직접 스프링 빈 등록하기 자바 코드로 직접 스프링 빈 등록하 회원 서비스와 회원 리포지토리의 @Service, @Repository, @Autowired 애테이션을 제거하고 진행한다. 위 애노테이션 제거 시 정상 작동 안 됨 💾 main > java > hello > hellospring > SpringConfig package hello.hellospring; import hello.hellospring.repository.MemberRepository; import hello.hellospring.repository.MemoryMemberRepository; import hello.hellospring.service.MemberService; import org.springframework.context.annotation... 2023. 2. 21.
[자바/스프링] 스프링 빈과 의존관계 스프링 빈과 의존관계 회원 컨트롤러가 회원서비스와 회원 리포지토리를 사용할 수 있게 의존관계를 준비하자. 화면을 붙이고 싶은데, 그러려면 controller랑 view template이 필요함. 회원가입을 하고, 회원 가입된 결과를 HTML로 뿌려준다. memberController가 memberService를 통해 회원가입을 하고, memberService를 통해 데이터를 조회할 수 있어야 한다. 이렇게 되는 걸 의존 관계가 있다고 표현한다. 💾 main > controller > MemberController package hello.hellospring.controller; import org.springframework.stereotype.Controller; @Controller public c.. 2023. 2. 20.
[자바/스프링] API (getter, setter, json) 💾 main > java > hello > hellospring > controller > HelloSpringApplication package hello.hellospring.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; @Controller public.. 2023. 2. 14.