๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ 

๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ 

19. Null-safety

์Šคํ”„๋ง ํ”„๋ ˆ์ž„์›Œํฌ 5์— ์ถ”๊ฐ€๋œ Null ๊ด€๋ จ ์• ๋…ธํ…Œ์ด์…˜ org.springframework.lang.* @NonNull @Nullable @NonNullApi (ํŒจํ‚ค์ง€ ๋ ˆ๋ฒจ ์„ค์ •) @NonNullField (ํŒจํ‚ค์ง€ ๋ ˆ๋ฒจ ์„ค์ •) ๋ชฉ์  (ํˆด์˜ ์ง€์›์„ ๋ฐ›์•„) ์ปดํŒŒ์ผ ์‹œ์ ์— ์ตœ๋Œ€ํ•œ NPE(NullPointerException)์„ ๋ฐฉ์ง€ํ•˜๋Š” ๊ฒƒ null ์ฒดํฌ๋ฅผ ํ•˜์ง€ ์•Š์•„์„œ ์ƒ๊ธฐ๋Š” NPE ๋ฐฉ์ง€ @NonNull org.springframework.lang.NonNull ์‚ฌ์šฉ ๋ฉ”์†Œ๋“œ ํŒŒ๋ผ๋ฏธํ„ฐ์— ๋ถ™์ด๋Š” ๊ฒฝ์šฐ -> null ๊ฐ’์ด ๋“ค์–ด์˜ค์ง€ ๋ชปํ•˜๋„๋ก ๋ฐฉ์ง€ @Service public class EventService { @NonNull // (1) public String createEvent(@NonNull String na..

๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ 

18. ์Šคํ”„๋ง AOP : @AOP

์• ๋…ธํ…Œ์ด์…˜ ๊ธฐ๋ฐ˜์˜ ์Šคํ”„๋ง @AOP ์˜์กด์„ฑ ์ถ”๊ฐ€ org.sringframework.boot spring-boot-starter-aop Aspect ์ •์˜ @Aspect ๋นˆ์œผ๋กœ ๋“ฑ๋กํ•ด์•ผ ํ•˜๋‹ˆ๊นŒ (์ปดํฌ๋„ŒํŠธ ์Šค์บ”์„ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด) @Component๋„ ์ถ”๊ฐ€ ํฌ์ธํŠธ์ปท ์ •์˜ @PointCut(ํ‘œํ˜„์‹) ์ฃผ์š” ํ‘œํ˜„์‹ execution @Service public class SimpleEventService implements EventService{ @Override public void createEvent() { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("create an Eve..

๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ 

17. ์Šคํ”„๋ง AOP : ํ”„๋ก์‹œ ๊ธฐ๋ฐ˜ AOP

์Šคํ”„๋ง AOP ํŠน์ง• ํ”„๋ก์‹œ ๊ธฐ๋ฐ˜์˜ AOP ๊ตฌํ˜„์ฒด ์Šคํ”„๋ง ๋นˆ์—๋งŒ AOP๋ฅผ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ๋ชจ๋“  AOP ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ์ด ๋ชฉ์ ์ด ์•„๋‹ˆ๋ผ, ์Šคํ”„๋ง IoC์™€ ์—ฐ๋™ํ•˜์—ฌ ์—”ํ„ฐํ”„๋ผ์ด์ฆˆ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ๊ฐ€์žฅ ํ”ํ•œ ๋ฌธ์ œ(์ค‘๋ณต์ฝ”๋“œ, ํ”„๋ก์‹œ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“œ๋Š” ๋น„์šฉ๊ณผ ์ˆ˜๊ณ , ๊ฐ์ฒด๋“ค ๊ฐ„ ๊ด€๊ณ„ ๋ณต์žก ๋“ฑ๋“ฑ)์— ๋Œ€ํ•œ ํ•ด๊ฒฐ์ฑ…์„ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ์ด ๋ชฉ์ . ํ”„๋ก์‹œ ํŒจํ„ด (๊ธฐ์กด ์ฝ”๋“œ ๋ณ€๊ฒฝ ์—†์ด) ์ ‘๊ทผ ์ œ์–ด ๋˜๋Š” ๋ถ€๊ฐ€ ๊ธฐ๋Šฅ ์ถ”๊ฐ€ ํ”„๋ก์‹œ ํŒจํ„ด์„ ์ด์šฉํ•˜์—ฌ ๊ธฐ์กด ์ฝ”๋“œ๋ฅผ ๊ฑด๋“œ๋ฆฌ์ง€ ์•Š๊ณ  ์„ฑ๋Šฅ์„ ์ธก์ •ํ•ด๋ณด๊ฒ ๋‹ค. @Component public class AppRunner implements ApplicationRunner { @Autowired EventService eventService; //interface๊ฐ€ ์žˆ๋‹ค๋ฉด interfaceํƒ€์ž…์œผ๋กœ ๋ฐ›๋Š”๊ฒŒ ..

๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ 

16. ์Šคํ”„๋ง AOP : ๊ฐœ๋… ์†Œ๊ฐœ

Aspect-oriented Programming (AOP)์€ OOP๋ฅผ ๋ณด์™„ํ•˜๋Š” ์ˆ˜๋‹จ์œผ๋กœ, ํฉ์–ด์ง„ Aspect๋ฅผ ๋ชจ๋“ˆํ™” ํ•  ์ˆ˜ ์žˆ๋Š” ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ธฐ๋ฒ•. ํฉ์–ด์ง„ ๊ด€์‹ฌ์‚ฌ (Crosscutting *Concerns) *Concerns : ๋น„์Šทํ•œ ์ฝ”๋“œ, ๋น„์Šทํ•œ ํ˜ธ์ถœ ๋“ฑ๋“ฑ. AOP๋ฅผ ์ ์šฉ ํ•˜๋ฉด? Aspect๋กœ ํฉ์–ด์ง„ ๊ฒƒ๋“ค์„ ํ•œ๊ณณ์œผ๋กœ ๋ชจ์€๋‹ค. AOP ์ฃผ์š” ๊ฐœ๋… Aspect ์™€ Target Advice Join point ๊ณผ Pointcut Aspect : ํฉ์–ด์ง„ ๊ด€์‹ฌ์‚ฌ๋ฅผ ํ•œ๊ณณ์œผ๋กœ ๋ชจ๋“ˆํ™” ํ•œ ๊ฒƒ. Advice : ์–ด๋–ค ์ผ์„ ํ•ด์•ผ ํ•˜๋Š”์ง€์— ๋Œ€ํ•œ ์ •๋ณด. Join point : ์ƒ์„ฑ์ž ํ˜ธ์ถœํ•˜๊ธฐ ์ง์ „, ์ƒ์„ฑ์ž๋ฅผ ํ˜ธ์ถœํ–ˆ์„๋•Œ, ํ•„๋“œ์—์„œ ๊ฐ’์„ ๊ฐ€์ ธ๊ฐ”์„๋•Œ...๋“ฑ๋“ฑ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ํ•ฉ๋ฅ˜์ . Pointcut: A๋ผ๋Š” ํด๋ž˜์Šค์— b๋ผ๋Š” ๋ฉ”์†Œ๋“œ๋ฅผ ..

๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ 

15. SpEL ( ์Šคํ”„๋ง Expression Language)

์Šคํ”„๋ง ELโ€‹์ด๋ž€? ์Šคํ”„๋ง ํ”„๋กœ์ ํŠธ ์ „๋ฐ˜์— ๊ฑธ์ณ ํ•„์š”๋กœ ํ•˜๋‹ค๋ณด๋‹ˆ๊นŒ, Unified EL ์— ๋ฉ”์†Œ๋“œ ํ˜ธ์ถœ ๊ธฐ๋Šฅ๊ณผ, ๋ฌธ์ž์—ด ํ…œํ”Œ๋ฆฟ ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•˜์—ฌ ์Šคํ”„๋ง์ด SpEL์„ ๊ฐœ๋ฐœํ•˜๊ฒŒ ๋œ๊ฒƒ์ด๋‹ค. ๊ฐ์ฒด ๊ทธ๋ž˜ํ”„๋ฅผ ์กฐํšŒํ•˜๊ณ  ์กฐ์ž‘ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•œ๋‹ค. Unified ELโ€‹๊ณผ ๋น„์Šทํ•˜์ง€๋งŒ, ๋ฉ”์†Œ๋“œ ํ˜ธ์ถœ์„ ์ง€์›ํ•˜๋ฉฐ, ๋ฌธ์ž์—ด ํ…œํ”Œ๋ฆฟ ๊ธฐ๋Šฅ๋„ ์ œ๊ณตํ•œ๋‹ค. OGNL, MVEL, JBOss EL ๋“ฑ ์ž๋ฐ”์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์—ฌ๋Ÿฌ EL์ด ์žˆ์ง€๋งŒ, SpEL์€ ๋ชจ๋“  ์Šคํ”„๋ง ํ”„๋กœ์ ํŠธ ์ „๋ฐ˜์— ๊ฑธ์ณ ์‚ฌ์šฉํ•  EL๋กœ ๋งŒ๋“ค์—ˆ๋‹ค. ์Šคํ”„๋ง 3.0 ๋ถ€ํ„ฐ ์ง€์›. SpEL ๊ตฌ์„ฑ ExpressionParser expressionParser = new SpelExpressionParser(); Expression expression = expressionParser...

๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ 

14. ๋ฐ์ดํ„ฐ ๋ฐ”์ธ๋”ฉ ์ถ”์ƒํ™” : Converter ์™€ Formatter

Converter S ํƒ€์ž…์„ T ํƒ€์ž…์œผ๋กœ ๋ณ€ํ™˜ํ•  ์ˆ˜ ์žˆ๋Š” ๋งค์šฐ ์ผ๋ฐ˜์ ์ธ ๋ณ€ํ™˜๊ธฐ ์ƒํƒœ ์ •๋ณด ์—†์Œ == Stateless = ์“ฐ๋ ˆ๋“œ์„ธ์ดํ”„ public class EventConverter { public static class StringToEventConverter implements Converter{ @Override public Event convert(String source) { return new Event(Integer.parseInt(source)); }//String์—์„œ Event๋กœ Event/Constructor์— source๋ฅผ ๋„˜๊ธด๋‹ค. } public static class EventToString implements Converter{ @Override public String con..

iseunghan
'๐Ÿ’ Spring/Spring ํ•ต์‹ฌ ๊ธฐ์ˆ ' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก