๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ’Š Java & Kotlin & Spring/- Spring37

[Spring] ApplicationEventPublisher ๋ฅผ ์ด์šฉํ•ด์„œ Event ๋ฅผ ๋ฐœํ–‰ํ•˜๋ฉด ์–ด๋–ค ์ผ์ด ์ผ์–ด๋‚ ๊นŒ ํ•ด๋‹น ๊ธ€์˜ ์ „์ฒด ์†Œ์Šค์ฝ”๋“œ๋Š” github ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. README ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š” ๋ชฉ์ฐจ ๋™๊ธฐ There is No Magic in spring ๋™๊ธฐ ์ตœ๊ทผ์— DDD ๋ฅผ ํ•™์Šตํ•˜๋ฉด์„œ ๋„๋ฉ”์ธ ์ด๋ฒคํŠธ๋ผ๋Š” ๊ฒƒ์„ ์•Œ๊ฒŒ ๋˜์—ˆ๋‹ค. ๊ทธ๋Ÿฌ๋ฉด์„œ Spring ์—์„œ ํ•œ VM ์•ˆ์—์„œ ์ด๋ฒคํŠธ๋ฅผ ๋ฐœํ–‰ํ•˜๊ณ  ํ•ด๋‹น ์ด๋ฒคํŠธ๋ฅผ handling ํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ์ ‘ํ–ˆ๊ณ , ๊ทธ์™€ ๊ด€๋ จํ•ด์„œ ์—ฌ๋Ÿฌ ์‹ค์Šต์„ ํ•ด๋ณด๋˜ ์ค‘ Spring ์—์„œ ๋ฌด์–ธ๊ฐ€ Magic ์ด ์ผ์–ด๋‚˜๊ณ  ์žˆ๋Š”๊ฒƒ ๊ฐ™์€ ๋Š๋‚Œ์„ ๋ฐ›์•˜๋‹ค. ๊ธด ๋ง ํ•„์š” ์—†์ด ์•„๋ž˜์˜ ์ฝ”๋“œ๋ฅผ ํ™•์ธํ•ด๋ณด์ž. @Entity(name = "orders") public class Order { public static Order create() { return new Order(); } @Id private Long id; .. 2022. 8. 15.
[Spring Boot] CORS ๋ฅผ ํ•ด๊ฒฐํ•˜๋Š” 3๊ฐ€์ง€ ๋ฐฉ๋ฒ• (Filter, @CrossOrigin, WebMvcConfigurer) Server Side Template ๋ฐฉ์‹์ด ์•„๋‹Œ Front์™€ Back ์œผ๋กœ ๋‚˜๋ˆ ์„œ ์ธํ”„๋ผ๋ฅผ ๊ตฌ์„ฑํ•ด๋ณธ ๊ฒฝํ—˜์ด ์žˆ๋Š” ์‚ฌ๋žŒ๋“ค์—๊ฒŒ๋Š” Cors๊ฐ€ ๋งค์šฐ ์นœ์ˆ™ํ•  ์ˆ˜ ์žˆ๋‹ค. ํ˜„์žฌ ๊ฐœ๋ฐœ ํ๋ฆ„์—์„œ ์›น ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋‹ค๊ฐ€ Cors ๋ฅผ ๋งŒ๋‚  ํ™•๋ฅ ์€ ๊ฐ€ํžˆ 100% ๋ผ๊ณ  ํ•ด๋„ ๊ณผ์–ธ์ด ์•„๋‹ˆ๋‹ค. ์˜ค๋Š˜์€ CORS ๊ฐ€ ๋ฌด์—‡์ธ์ง€ ์•Œ์•„๋ณด๋ฉฐ ๋˜, Spring Boot Application ์—์„œ๋Š” ์–ด๋–ป๊ฒŒ ํ•ด๋‹น ์ •์ฑ…์„ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ์•Œ์•„๋ณด์ž. CORS ํ•ด๊ฒฐํ•˜๊ธฐ ์šฐ์„  ๊ฐ€์žฅ ๋จผ์ € ๋ง ํ•˜๊ณ  ์‹ถ์€ ๊ฒƒ์€ CORS ๋Š” ์—๋Ÿฌ๋‚˜ ์˜ค๋ฅ˜๊ฐ€ ์•„๋‹ˆ๋‹ค. Cross-Origin Resource Sharing Policy ์ด๋‹ค. ์ฒ˜์Œ ๋‚ด๊ฐ€ Front ์™€ Back ์„ ๋‚˜๋ˆ ์„œ ๊ฐœ๋ฐœ์„ ํ•  ๋•Œ์—๋Š” ๋‹จ์ˆœํžˆ Front ์—์„œ fetch ์š”์ฒญ์œผ๋กœ Back ์„ ๋ฐ”๋ผ๋ณด๊ณ  ๋‚ ๋ฆฌ๋ฉด ๋ .. 2021. 8. 14.
[Spring Boot] Profile.active ์„ ์ด์šฉํ•˜์—ฌ ๋‹ค๋ฅธ ์„ค์ • ์ •๋ณด(application.properties) ๋ถˆ๋Ÿฌ์˜ค๊ธฐ application.properties ํŒŒ์ผ ์šฐ๋ฆฌ๋Š” application.yml ์ด๋‚˜ application.properties ํŒŒ์ผ์„ ์ด์šฉํ•ด์„œ ์„ค์ • ์ •๋ณด๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณค ํ•œ๋‹ค. server: port: 56237 spring: application: name: user-service datasource: url: 232.221.123.33 driver: h2.Driver username: ffowidl123 password: "{cipher}ff01fjosdifj02034j5;jasdj5rq239y48f" ์šฐ๋ฆฌ๊ฐ€ ๊ฐœ๋ฐœํ•˜๋Š” application์€ ๋‹ค์–‘ํ•œ ํ™˜๊ฒฝ์—์„œ ๊ฐœ๋ฐœ๋˜์–ด์ง„๋‹ค. ์ด๋ฅผํ…Œ๋ฉด ๊ธฐ๋Šฅ ๊ฐœ๋ฐœ์„ ์œ„ํ•œ dev ํ™˜๊ฒฝ, ๊ธฐ๋Šฅ ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•œ test ํ™˜๊ฒฝ, ๊ธฐ๋Šฅ ๋ฐฐํฌ๋ฅผ ์œ„ํ•œ production ํ™˜๊ฒฝ ๋“ฑ๋“ฑ ๊ฐ๊ฐ์— ๋งž.. 2021. 4. 26.
[Spring Boot] ํ„ฐ๋ฏธ๋„์—์„œ ๋นŒ๋“œ ํˆด (Maven, Gradle)๋กœ Spring Boot ์‹คํ–‰์‹œํ‚ค๊ธฐ ์˜ค๋Š˜์€ ํ„ฐ๋ฏธ๋„์—์„œ Springboot Application ์„ ์‹คํ–‰์‹œํ‚ค๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๋ ค ํ•œ๋‹ค. ํ˜„์žฌ Microservice Application ์„ ๊ฐœ๋ฐœํ•˜๊ธฐ ์œ„ํ•ด์„œ ์ฃผ๋กœ Eureka์™€ Gateway ๋ฅผ ํ•จ๊ป˜ ๋™์ž‘์‹œํ‚ค๋Š” ์ผ์ด ๋งŽ์•„์กŒ๋‹ค. Service Discovery ์—ญํ• ์„ ์ˆ˜ํ–‰ํ•˜๋Š” Eureka ์„œ๋ฒ„๋Š” ๋‹จ์ง€ ์„œ๋น„์Šค์˜ Registry์™€ Discovery ์ƒํ™ฉ์—์„œ ์ผœ๋†“๊ณ ๋งŒ ์žˆ์–ด์•ผ ํ•˜๋Š” ์ƒํ™ฉ์ด ์ž์ฃผ ๋ฐœ์ƒํ•˜๋Š”๋ฐ, ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์—์„œ ๊ธฐ๋Šฅ ๊ฐœ๋ฐœ์„ ์œ„ํ•ด์„œ๋Š” Eureka ์„œ๋ฒ„์™€ Gateway ๋ฅผ Intellij ์—์„œ ์ผœ๋†“๋Š” ๊ฒƒ์ด ๋Œ€๋‹ค์ˆ˜์ด๋‹ค. ํ•˜์ง€๋งŒ Intellij ๋Š” ๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ์„ ๊ฐ–๊ณ ์žˆ๋Š” ์กฐ๊ธˆ ๋ฌด๊ฑฐ์šด IDE ์ด๊ธฐ ๋•Œ๋ฌธ์— ํ•ด๋‹น PC์˜ ๋ฆฌ์†Œ์Šค๋ฅผ ๋งŽ์ด ๋จน์–ด ๋ถˆํŽธํ•œ ์ƒํ™ฉ์ด ์ด๋งŒ์ €๋งŒ์ด ์•„๋‹ˆ๋‹ค. ๊ทธ๋Ÿด ๋•Œ ๋งŽ์€ ํ•ด๊ฒฐ ๋ฐฉ.. 2021. 4. 24.