본문 바로가기

SpringBoot9

Spring @RestControllerAdvice 적용 @RestControllerAdvice @RestControllerAdvice (@ControllerAdvice)는 전역으로 예외 처리할 수 있게 해주는 Annotation 이를 통해 각 Controller 별로 예외 처리 코드를 작성하여 중복 코드가 발생하는 것을 해결할 수 있고, 서비스 코드와 예외 처리 코드를 분리할 수 있음 패키지 단위 적용 basePackages에 package 경로를 명시하여 해당 package내에 적용 @Slf4j @RestControllerAdvice(basePackages = {"com.example.demo.ctl"}) // 여러개 추가 가능 public class DemoControllerAdvice { @ExceptionHandler public CommonRespo.. 2023. 11. 9.
Spring Boot & Thymeleaf 토이 프로젝트 [Course Registration System] Course Registration System Spring Boot와 Thymeleaf로 구현한 수강신청 웹 사이트 토이 프로젝트입니다. 개인 프로젝트로 진행했고, HTML 부분은 영한님의 스프링 강의에서 사용했던 HTML 코드를 수정하여 사용했습니다. Course Registration System Github https://github.com/wadekang/course-registration-system GitHub - wadekang/course-registration-system: Spring Boot 수강신청 웹 사이트 토이 프로젝트 Spring Boot 수강신청 웹 사이트 토이 프로젝트. Contribute to wadekang/course-registration-system develop.. 2022. 4. 1.
Spring JUnit5 Sql script로 테스트 데이터 불러오기 테스트를 할 때 sql로 미리 데이터를 insert 하고 해당 데이터로 테스트를 진행하고 싶을 경우 다음과 같이 설정하면 된다. 먼저 테스트 폴더에 resources 폴더를 만들어서 applciation.yml (or properties)을 설정해준다. spring: datasource: url: jdbc:h2:mem:testdb;MODE=MYSQL;DB_CLOSE_DELAY=-1 username: sa password: driver-class-name: org.h2.Driver jpa: properties: hibernate: dialect: org.hibernate.dialect.MySQL5InnoDBDialect storage-engine: innodb hibernate: ddl-auto: crea.. 2022. 3. 17.
[Spring][Error] Spring Security 적용할 때 circular reference, dependency가 cycle 형성하는 것 해결하기 SecurityConfig @RequiredArgsConstructor @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { ... private final UserService userService; @Bean public BCryptPasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.userDetailsService(userService).passwordEn.. 2022. 3. 14.
AWS RDS(MariaDB)와 IntelliJ Database 연동하기 - [스프링 부트와 AWS로 혼자 구현하는 웹 서비스] AWS RDS(MariaDB)와 IntelliJ Database Navigator 연동 과정에서 오류 Versions IntelliJ IDEA 2021.3.1 (Ultimate Edition) Spring Boot 2.6.4 JDK 11 MariaDB(AWS RDS) 10.5.13 [스프링 부트와 AWS로 혼자 구현하는 웹 서비스] 책을 따라 실습하던 중에 Chapter 07의 AWS RDS를 생성하고 인텔리제이의 데이터베이스와 연동하는 과정에서 DB Navigator를 설치하고 아래와 같이 필드를 채운 후 Test Connection을 시도했다. 하지만 위와 같이 Connection error가 발생했다. 구글링을 계속 해보다가 마땅한 답이 없어서 인텔리제이 Ultimate 버전을 사용하고 있기 때문에.. 2022. 3. 5.
SpringBoot 간단한 CRUD REST API 구현 및 JUnit5로 테스트하기 REST API란? REST API는 REST(representational state transfer)를 기반으로 하여 HTTP 요청을 사용하여 데이터에 액세스하고 사용하는 API의 아키텍처 스타일입니다. CRUD란? API를 구축할 때 모델이 제공하는 4가지 기본 유형의 기능, Create(생성), Read(읽기), Update(수정), Delete(삭제)를 CRUD라고 합니다. CRUD 구현 (Entity, Repository, Service, Controller) JPA와 H2 데이터베이스를 사용하여 간단하게 구현했습니다. User.java (Entity) package com.example.practice.impl; import lombok.Builder; import lombok.Getter;.. 2022. 2. 26.