본문 바로가기

Spring Boot7

[Framework] Spring Boot [STS 설치 + Git 프로젝트 Import + Tomcat 실행] Spring Tools for Eclipse 기준 설명 1. https://spring.io/tools 접속하여 STS(for Eclipse) 설치 후 실행 2. 상단 Quick Access에 Git Repositories 검색 후 클릭 3. Git Repositories 탭으로 가서 Clone a Git repository 4. gitlab 사이트 Import 하려는 프로젝트로 들어가서 Clone -> Clone with HTTPS 부분 복사 5. STS로 돌아가서 URL 부분에 붙여넣기 하면 세부 항목까지 자동 입력(Port는 빈칸) 6. master 브랜치 체크 후 Next & Finish 7. Git Repositories 탭의 프로젝트 우클릭 후 Import Projects 8. Package .. 2023. 10. 5.
[Framework] Spring Boot [@Autowired & private final] 의존성 주입 방식 1. @Autowired (필드 주입 : Field Injection) 참고 : 필드를 final로 선언 불가 @Service public class ArticleService { @Autowired private ArticleRepository articleRepository; } 2. private final (생성자 주입 : Constructor Injection) @Service public class ArticleService { private final ArticleRepository articleRepository; public ArticleService(ArticleRepository articleRepository) { this.articleRepository = art.. 2022. 11. 30.
[Framework] Spring Boot [JWT] 인증 구현 맛보기 Spring Boot에서 JWT를 활용한 인증 구현 세션 VS 토큰 [세션] 1. 클라이언트가 로그인 요청을 하고, 로그인 정보가 일치하면 서버는 세션을 생성/유지 (클라이언트마다 하나씩) (세션에는 사용자 ID, 로그인 시간, IP 등을 저장) 2. 서버는 로그인 응답 (세션을 찾을 수 있는 세션 ID를 클라이언트에 전달 (보통 쿠키로 전달)) (세션은 서버에 저장되는 값, 쿠키는 클라이언트에 저장되는 값) 3. 클라이언트가 세션 ID와 함께 서비스 요청을 하면 서버는 세션 ID로 세션을 찾아 인증된 유저임을 확인 4. 서버는 서비스 응답 서버가 세션을 들고있다. 서버가 1대라면 세션을 사용해도 괜찮지만, 서버는 여러 대가 존재할 것이다. (모두 세션을 가져야 함 & 동기화) 세션 클러스터링 등 작업이.. 2022. 11. 30.
[Framework] Spring Boot [TDD] 테스트 코드 작성 TDD(Test Driven Development)란? 테스트 코드를 만들고, 이를 통과하는 최소한의 코드로 시작하여 점진적으로 개선, 확장해가는 개발 방식을 말한다. Article 서비스를 검증하는 테스트 코드를 작성해보자 Article 서비스에서 테스트를 원하는 메소드명 우클릭 Generate > Test를 클릭하고 열린 창 하단에 테스트를 할 메소드명을 체크 후 OK를 클릭한다. ArticleServiceTest라는 클래스 파일이 만들어지고 이 파일의 경로는 src > test > java > com.example.firstproject > service가 된다. H2 DB를 사용하고 있었기 때문에 data.sql을 참고해 테스트 코드를 작성한다. 예상 시나리오 작성 -> 실제 결과와 비교하여 검증.. 2022. 11. 30.
[Framework] Spring Boot [REST API] 기본 구조 1. DTO + ApiController + Entity + Repository 구조 (Service 계층 없을 경우) Client : 손님 RestController(Server) : 웨이터 & 셰프 Repository(Server) : 주방 보조 DataBase : 창고 src > main > java > com.example.firstproject > api의 ArticleApiController package com.example.firstproject.api; import com.example.firstproject.dto.ArticleDto; import com.example.firstproject.entity.Article; import com.example.firstproject.repos.. 2022. 11. 30.
[Framework] Spring Boot [JPA + H2] 기초 # H2 DB, 웹 콘솔 접근 허용 spring.h2.console.enabled=true # 실행과 동시에 데이터 생성 가능하도록 변경 spring.jpa.defer-datasource-initialization=true # JPA 로깅 설정 # 디버그 레벨로 쿼리 출력 logging.level.org.hibernate.SQL=DEBUG # 정리해서 보여주기 spring.jpa.properties.hibernate.format_sql=true # 파라미터 보여주기 logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE # DB URL 고정 설정 # 유니크 URL 생성 X spring.datasource.generate-unique-name=.. 2022. 11. 30.