분류 전체보기 1341

API 스펙 정의

회원 가입 API POST {host}/api/v1/users/signup { "email" : "dev@gmail.com", "password" : "", "username" : "사용자" } 응답 200 OK 로그인 API POST {host}/api/v1/users/signin { "email" : "dev@gmail.com", "password" : "", } 응답 { "email" : "", "username" : "", "token" : "", "refreshToken" : "" } 로그아웃 API DELETE {host}/api/v1/users/logout header=Authorization : Bearer {token} 응답 204 NO_CONTENT 내 정보 조회 API GET {hos..

프로젝트 구성하기

Module 생성 Main @SpringBootApplication @ConfigurationPropertiesScan //프로퍼티 스캔 class FastcampusUserServiceApplication { } fun main(args: Array) { runApplication(*args) } Build.gradle plugins { id("java") } group = "com.fastcampus" version = "0.0.1-SNAPSHOT" repositories { mavenCentral() } dependencies { implementation("org.springframework.boot:spring-boot-starter-data-r2dbc") implementation("org.s..

채널

코루틴은 채널을 통해 데이터를 전달/전송 받는다. 코루틴 채널 종류 https://kotlinlang.org/docs/coroutines-and-channels.html#testing-coroutines Unlimited channel Unlimited channel 은 큐에 가장 가까운 채널이다. 생산자들은 이 채널에 요소를 무제한 요소를 보낼 수 있다. send() 호출은 중단되지 않으며, 프로그램에 메모리가 부족하면, 메모리 부족 예외가 발생한다 큐와 Unlimited channel 차이는 소비자가 빈 채널에서 receive()를 시도할 때, 새로운 요소가 전송될 때까지 중단된다는 차이점이 있다. Buffered channel 버퍼링된 채널의 크기는 지정된 숫자에 의해 제한되고, 생산자는 크기 제한..

자동 설정에 의한 초기화 진행

SpringWebMvcImportSelector : 인터페이스로, 특정 환경에 따라 다른 설정 파일을 Load 할 수 있도록 도와준다. SecurityFilterAutoConfiguration : DelegatingFilterProxyRegistrationBean이라는 빈 클래스를 만들고, 이 빈클래스는 DelegatingFilterProxy를 등록시켜주는 역할을 한다 DelegatingFilterProxy는 SpringSecurityFilterChain 이름의 빈을 검색하고, 그 빈에게 클라이언트 요청을 위임하는 역할을 한다. WebMvcSecurityConfiguration : ArgumentResolver 관련 타입을 클래스를 생성해준다 AuthenticationPrincipalArgumentRes..

코루틴 기초

runBlocking fun main() { runBlocking {// 코루틴을 생성하는 코루틴 빌더, 런블록킹 함수로 감싼 코드는 코루틴 내부에 코드가 끝날때 까지 해당 스레드를 블록킹한다. //일반적인 코드(스프링 MVC, 스프링 배치)와 같은 코드를 실행시킬때 사용한다. println("Hello ") println("Thread : ${Thread.currentThread().name} ") //실행 옵션에 coroutine 옵션을 켜야지만 보인다. } println("World") println(Thread.currentThread().name) } runBlocking은 코루틴을 생성하는 코루틴 빌더이다. runBlocking으로 감싼 코드는 코루틴 내부의 코드가 수행이 끝날 때까지 스레드가..

스프링 WebFlux의 코루틴 지원

스프링 WebFlux 코루틴 지원 프로젝트 리액터 기반의 리액티브 프로그래밍은 비동기/Non-Blocking의 단점인 콜백 헬 문제를 순차적으로 동작하는 연산자를 통해 해결했다. 기존 함수형 패러다임에 익숙하거나, 리액터의 다양한 연산자에 대한 학습이 부담이 없다면 리액티브 프로그래밍은 비동기/Non-Blocking 코드 작성 시 매우 좋은 솔루션이나, 러닝 커브가 너무 높다. 안드로이드도 최근에 RxJava에서 코루틴 기반으로 작성하는 코드가 늘어나고 있으며, 서버 측에서도 코루틴을 도입하는 사례가 많아지고 있다. 코루틴 suspend fun combineApi() = coroutineScope { val response1 = async { getApi1() } val response2 = async ..

스프링 데이터 R2DBC

JDBC String selectSql = "SELECT * FROM employees"; try (ResultSet resultSet = stmt.executeQuery(selectSql)) { List employees = new ArrayList(); while (resultSet.next()) { Employee emp = new Employee(); emp.setId(resultSet.getInt("emp_id")); emp.setName(resultSet.getString("name")); emp.setPosition(resultSet.getString("position")); emp.setSalary(resultSet.getDouble("salary")); employees.add(emp);..

웹클라이언트

RestTemplate //RestTemplate 은 더이상 사용되지 않는 duplicate 되었다 val url = "http://localhost:8080/books" val log = LoggerFactory.getLogger(javaClass) @GetMapping("/books/block") fun getBooksBlockingWay(): List { log.info("Start RestTemplate") val restTemplate = RestTemplate() val response = restTemplate.exchange(url, GET, null, object : ParameterizedTypeReference() {}) //RestTemplate는 코드가 순차적으로 흐르기 때문에 코..

애노테이션 컨트롤러

애노테이션 컨트롤러 @RestController //웹 플럭스에서도 동일하게 애노테이션을 사용할 수 있다. class HelloController { @GetMapping fun hello() = "Hello WebFlux" } WebFlux에서 제공하는 애노테이션 컨트롤러 모델은 전통적인 SpringMVC에서 사용하던 애노테이션 기반의 요청, 응답을 그대로 사용할 수 있다. Book 서비스 개발 Controller @RestController class BookController( private val bookService: BookService, ) { @GetMapping("/books") fun getAll(): Flux { //스프링에서 반환 타입이, Flux,Subscribe 일 경우 알아서 ..

초기화 과정 이해(SecurityBuilder / SecurityConfigurer)

프로젝트 생성 스프링 시큐리티 의존성만 추가하더라도, 기본적으로 User/Password를 제공이 된다. SecurityBuilder / SecurityConfigurer SecurityBuilder는 빌더 클래스로, 웹 보안을 구성하는 빈 객체와 설정 클래스들을 생성하는 역할을 하며, WebSecurity와 HttpSecurity가 있다. SecurityConfigurer는 Http 요청과 관련된 보안 처리를 담당하는 필터들을 생성하고, 여러 초기화 설정에 관여한다. SecurityBuilder는 SecurityConfigurer를 포함하고 있으며, 인증 및 인가 초기화 작업은 SecurityConfigurer에 의해 진행된다. build() 메서드를 통해 빌더 클래스 생성 빌더 클래스를 생성하는 과정..