Spring/Spring & Spring Boot
์ฝ๋๋ฅผ ๋ณด๋ค๊ฐ Example ์ธํฐํ์ด์ค๋ฅผ ํ์ฉํ ๊ฒฝ์ฐ๊ฐ ์์๋ค. Example๋ฅผ ์ธ์ ์ฌ์ฉํ๊ณ , ์ ์ฌ์ฉํ๋์ง ์์๋ณด์. Example ์ธํฐํ์ด์ค๋ ?Spring Data Core์์ ์ ๊ณตํ๋ ๊ฒ์ผ๋ก, QBE(Query By Example)์ ์ง์ํ๋ ๊ธฐ๋ฅ์ด๋ค. ๊ฐ์ฒด ์์ฒด๋ฅผ ์ฟผ๋ฆฌ ์กฐ๊ฑด์ผ๋ก ํ์ฉํ์ฌ ๊ฐ๋จํ ๊ฒ์์ ์ํํ ์ ์๋ค. ์ฃผ์ ๊ฐ๋
๋๋ฉ์ธ ๊ฐ์ฒด(์ํฐํฐ) ์์ฒด๋ฅผ ๊ฒ์ ์กฐ๊ฑด์ผ๋ก ํ์ฉNull ๊ฐ์ ๋ฌด์ (ํ๋ ๊ฐ์ด ์๋ ๊ฒ๋ง ๊ฒ์ ์กฐ๊ฑด์ผ๋ก ์ฌ์ฉ)๋์ ์ฟผ๋ฆฌ ์์ฑ ๊ฐ๋ฅ๋ณ๋์ JPQL์ด๋ SQL์ ์์ฑํ ํ์ ์์๐ ๊ฐ๋จํ ๊ฒ์์์๋ ์ ์ฉํ๊ฒ ์ผ๋.. ์ค๋ฌด์์๋ ๋ณต์กํ ๊ฒ์์ด ๋ ๋ง์ด ๋๋ฌธ์ ๊ทธ๋ฅ ์ ๋ฐ ๊ธฐ๋ฅ์ด ์๊ตฌ๋ ์ ๋๋ง ์์๋ ๋ ๊ฒ ๊ฐ๋ค. ์ฌ์ฉ ์์User probe = new User();..
Spring/๐ ์๋ฌ ๊ธฐ๋ก
๐ ์๋ฌ ์ค๋ช
class java.util.LinkedHashMap cannot be cast to class com.XXXX. XXXX.app.interfaces.devices.service.dto.StatusDto ๐ java.util.LinkedHashMap์ StatusDto ๊ฐ์ฒด๋ก ๊ฐ์ ๋ก ์บ์คํ
ํ๋ ค ํ ๋ ๋ฐ์ํ๋ ClassException์ด๋ค.Java์์ ํ์
๋ถ์ผ์น๋ก ์ธํด ๋ฐ์ํ๋๊ฑด๋ฐ, ์ ์ด๋ฌํ ์ํฉ์ด ๋ฐ์ํ๋์ง ์์๋ณด์... ์๋ฌ๊ฐ ๋ฐ์ํ๋ ์ํฉ๐ถ ์์ ์ ์ฝ๋ @Override public Flux getAll() { return deviceRepository.findByXXXX() .switchIfEmpty(Mono.error(n..
Spring/Spring WebFlux
Sequence ๋ณํ Operatorโณ๏ธ mapupstream์์ emit๋ ๋ฐ์ดํฐ๋ฅผ mapper function์ ์ฌ์ฉํด ๋ณํํ ํ, downstream์ผ๋ก emitmap() operator ๋ด๋ถ์์ ์๋ฌ ๋ฐ์ ์ sequence๊ฐ ์ข
๋ฃ๋์ง ์๊ณ ๊ณ์ ์งํ๋๋๋ก ํ๋ ๊ธฐ๋ฅ ์ง์ Mono mono = Mono.just("Reactor") .map(String::toUpperCase);mono.subscribe(System.out::println); // ์ถ๋ ฅ: REACTOR โณ๏ธ flatMapupstream์์ emit๋ ๋ฐ์ดํฐ๊ฐ Inner Sequence์์ ํํํ ์์
์ ๊ฑฐ์น๋ฉด์ ํ๋์ Sequence๋ก ๋ณํฉ๋์ด downstream์ผ๋ก emitpublic class Example { public..
Spring/Spring WebFlux
Spring WebFlux ๊ฐ์Spring 5.0๋ถํฐ ์ง์ํ๋ ๋ฆฌ์กํฐ๋ธ ์น ํ๋ ์์ํฌ๋ก, ์ ์ ์์ ์ค๋ ๋๋ก ๋๋์ ์์ฒญ์ ์์ ์ ์ผ๋ก ์ฒ๋ฆฌํ ์ ์๋ ๋น๋๊ธฐ Non-Blocking I/O ๋ฐฉ์์ ์ฌ์ฉํ๋ค. Spring WebFlux ๊ธฐ์ ์คํ โณ๏ธ Spring MVC์ Spring WebFlux ๊ธฐ์ ์คํ ๋น๊ต ๐ท ์๋ฒSpring MVC์๋ธ๋ฆฟ ๊ธฐ๋ฐ์ ํ๋ ์์ํฌApache Tomcat๊ฐ์ ์๋ธ๋ฆฟ ์ปจํ
์ด๋์์ Blocking I/O ๋ฐฉ์์ผ๋ก ๋์Spring WebFluxNon-Blocking I/O ๋ฐฉ์์ผ๋ก ๋์ํ๋ Netty ๋ฑ์ ์๋ฒ ์์ง์์ ๋์ ๐ท ์๋ฒ APISpring MVC์๋ธ๋ฆฟ API ์ฌ์ฉSpring WebFlux Jetty๋ Undertow ๊ฐ์ ์๋ฒ ์์ง์์ ์ง์ํ๋ ๋ฆฌ์กํฐ๋ธ ์ค..
Spring/Spring WebFlux
Operator๋ ?Reactive Stream์ ๋ฐ์ดํฐ ํ๋ฆ์ ์ฒ๋ฆฌํ๊ฑฐ๋ ๋ณํํ๋ ์ญํ ์ ํ๋ ๋ฉ์๋ ๐ท ํน์ง ๋น๋๊ธฐ ์ฒ๋ฆฌ์กฐํฉ ๊ฐ๋ฅ์ฑ์ง์ฐ ์คํ (๊ตฌ๋
์ด ํธ์ถ๋์ด์ผ ์ฒ๋ฆฌ)๋ฐ์ดํฐ ํ๋ฆ์ ๋จ๊ณ์ ์ผ๋ก ์ฒ๋ฆฌ Sequence ์์ฑ์ ์ํ Operatorโณ๏ธ justOrEmptyjust()์ ํ์ฅ operator๋ก์, emitํ ๋ฐ์ดํฐ๊ฐ null์ธ ๊ฒฝ์ฐ NullPooinException์ด ๋ฐ์ํ์ง ์๊ณ , onComplete signal์ ์ ์กjust()๋ Reactor์์ ๊ฐ๋จํ๊ณ ์ ์ ์ธ ๋ฐ์ดํฐ๋ฅผ Reactive Stream์ผ๋ก ๋ณํํ ๋ ์ ์ฉ- Hot Publisher์ด๊ธฐ ๋๋ฌธ์ Subscriber์ ๊ตฌ๋
์ฌ๋ถ์๋ ์๊ด์์ด ๋ฐ์ดํฐ๋ฅผ emit.- ๊ตฌ๋
์ด ๋ฐ์ํ๋ฉด emit๋ ๋ฐ์ดํฐ๋ฅผ ๋ค์ replayํด์ Sub..
Spring/Spring WebFlux
Sinks ๋ ?Reactor์์ ์ ๊ณตํ๋ Sinks๋ ๋น๋๊ธฐ ๋ฐ์ดํฐ๋ฅผ ์์ ํ๊ฒ ๋ฐํํ ์ ์๋ ์ ํธ๋ฆฌํฐ๋ก, Publisher ๋ฐ Subscriber ์ญํ ์ ์ง์ํ๋ค. ์ผ๋ฐ์ ์ผ๋ก generate() operator๋ create() operator๋ ์ฑ๊ธ์ค๋ ๋ ๊ธฐ๋ฐ์์ signal์ ์ ์กํ๋ ๋ฐ ์ฌ์ฉํ๋ ๋ฐ๋ฉด, Sinks๋ ๋ฉํฐ์ค๋ ๋ ๋ฐฉ์์ผ๋ก signal์ ์ ์กํด๋ ์ค๋ ๋ ์์ ์ฑ์ ๋ณด์ฅํ๊ธฐ ๋๋ฌธ์ ์๊ธฐ์น ์์ ๋์์ผ๋ก ์ด์ด์ง๋ ๊ฒ์ ๋ฐฉ์งํด์ค๋ค. ๐ก์ค๋ ๋ ์์ ์ฑ์ด๋ ? ํจ์๋ ๋ณ์ ๊ฐ์ ๊ณต์ ์์์ ๋์ ์ ๊ทผํ ๊ฒฝ์ฐ์๋ ํ๋ก๊ทธ๋จ์ ์คํ์ ๋ฌธ์ ๊ฐ ์์์ ์๋ฏธํ๋ค.๋์ ์ ๊ทผ์ ๊ฐ์งํ๊ณ , ๋์ ์ ๊ทผํ๋ ์ค๋ ๋ ์ค ํ๋๊ฐ ๋น ๋ฅด๊ฒ ์คํจํจ์ผ๋ก์จ ์ค๋ ๋ ์์ ์ฑ์ ๋ณด์ฅํ๋ค. Sinks ์ข
๋ฅ ๋ฐ ํน์ง โณ๏ธ Sink..
Spring/Spring WebFlux
Reactor๋ ? ๋ฆฌ์กํฐ๋ธ ํ๋ก๊ทธ๋๋ฐ์ ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ Spring Framework ํ์ ์ํด ๊ฐ๋ฐ๋ ๋ฆฌ์กํฐ๋ธ ์คํธ๋ฆผ์ฆ์ ๊ตฌํ์ฒด๋ก์ Spring WebFlux ๊ธฐ๋ฐ์ ๋ฆฌ์กํฐ๋ธ ์ดํ๋ฆฌ์ผ์ด์
์ ์ ์ํ๊ธฐ ์ํ ํต์ฌ ์ญํ ์ ๋ด๋นํ๋ค.โณ๏ธ Reactor์ ํน์ง Reactive StreamsNon-BlockingJava's Functional APIFlux[N]Mono[0|1]MicroservicesBackpressure Mono ๊ธฐ๋ณธ ์์ public class Example { public static void main(String[] args) { Mono .empty() .subscribe( none -> System.out.println(..
Spring/Spring WebFlux
1. ํจ์ํ ์ธํฐํ์ด์ค๋จ ํ๋์ ์ถ์ ๋ฉ์๋๋ง ์๋ ์ ์๋์ด์๋ ์ธํฐํ์ด์ค (Java 8๋ถํฐ ์ง์ ๊ฐ๋ฅ)ํจ์๋ฅผ ๊ฐ์ผ๋ก ์ทจ๊ธํ๊ธฐ ๋๋ฌธ์ ์ด๋ค ํจ์๋ฅผ ํธ์ถํ ๋ ํจ์ ์์ฒด๋ฅผ ํ๋ผ๋ฏธํฐ๋ก ์ ๋ฌ ๊ฐ๋ฅpublic class Example { public static void main(String[] args){ List cryptoCurrencies = SampleData.cryptoCurrencies; Collections.sort(cryptoCurrencies, new Comparator() { @Override public int compare(CryptoCurrency cc1, CryptoCurrency cc2) { r..