โœ๐ŸปLombok๊ณผ ์ตœ์‹  ํŠธ๋žœ๋“œ๐Ÿง

DEVJUNยท2021๋…„ 12์›” 23์ผ
0
post-thumbnail
post-custom-banner

์•ž์„œ ์ƒ์„ฑ์ž๋ฅผ ํ†ตํ•œ ์˜์กด๊ด€๊ณ„ ์ฃผ์ž…์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์•˜๋‹ค.

๊ทธ๋Ÿฐ๋ฐ ์ƒ์„ฑ์ž๋„ ๋งŒ๋“ค๊ณ , ์ฃผ์ž… ๋ฐ›์€ ๊ฐ’์„ ๋Œ€์ž…ํ•˜๋Š” ์ฝ”๋“œ ๋“ฑ ๋งŒ๋“ค์–ด์•ผ ํ•  ๊ฒƒ์ด ๋„ˆ๋ฌด ๋งŽ๋‹ค....

@Component์™€ @Autowired๋ฅผ ์ ์šฉํ•œ ๊ธฐ์กด ์ฝ”๋“œ์ด๋‹ค.

  @Component
  public class OrderServiceImpl implements OrderService {
      private final MemberRepository memberRepository;
      private final DiscountPolicy discountPolicy;
      
      @Autowired
      public OrderServiceImpl(MemberRepository memberRepository, DiscountPolicydiscountPolicy) {
          this.memberRepository = memberRepository;
          this.discountPolicy = discountPolicy;
      }
  }

์ƒ์„ฑ์ž๋ฅผ 1๊ฐœ๋งŒ ๋‘๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด @Autowired๋ฅผ ์ƒ๋žตํ•  ์ˆ˜ ์žˆ๋‹ค.

 @Component
  public class OrderServiceImpl implements OrderService {
      private final MemberRepository memberRepository;
      private final DiscountPolicy discountPolicy;
      
      public OrderServiceImpl(MemberRepository memberRepository, DiscountPolicydiscountPolicy) {
          this.memberRepository = memberRepository;
          this.discountPolicy = discountPolicy;
      }
  }

์ตœ๊ทผ์—๋Š” ์œ„์™€ ๊ฐ™์ด ์ƒ์„ฑ์ž๋ฅผ ๋”ฑ 1๊ฐœ๋งŒ ๋‘๊ณ  @Autowired๋ฅผ ์ƒ๋žตํ•˜๊ณ  ์‚ฌ์šฉํ•œ๋‹ค. ์—ฌ๊ธฐ์— Lombok๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ @RequiredArgsConstructor๋ฅผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๋ฉด, ์ฝ”๋“œ๊ฐ€ ๊น”๋”ํ•ด์ง„๋‹ค!!

๋‹ค์Œ ์ฝ”๋“œ๋Š” ์œ„ Lombok๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ ์šฉํ•œ ์ตœ์ข… ์ฝ”๋“œ์ด๋‹ค.

@Component
  @RequiredArgsConstructor
  public class OrderServiceImpl implements OrderService {
      private final MemberRepository memberRepository;
      private final DiscountPolicy discountPolicy;
}

๊ธฐ์กด ์ฝ”๋“œ์™€ ๋˜‘๊ฐ™์ด ๋™์ž‘ํ•œ๋‹ค. ์‹ค์ œ ํด๋ž˜์Šค๋ฅผ ์—ด์–ด๋ณด๋ฉด ๋‹ค์Œ ์ฝ”๋“œ๊ฐ€ ์ถ”๊ฐ€๋˜์–ด ์žˆ๋‹ค~!

  public OrderServiceImpl(MemberRepository memberRepository, DiscountPolicy discountPolicy) {
      this.memberRepository = memberRepository;
      this.discountPolicy = discountPolicy;
  }

๐Ÿ“์ด ๋ฐ–์—๋„ Lombok๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” @Getter / @Setter ๋“ฑ ๋‹ค์–‘ํ•œ ์• ๋…ธํ…Œ์ด์…˜์„ ํ†ตํ•ด ์ฝ”๋“œ๊ฐ€ ๋Š˜์–ด๋‚˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•˜๋ฉด์„œ ๊ฐœ๋ฐœ์— ํ•„์š”ํ•œ ๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•œ๋‹ค..

์ถœ์ฒ˜

https://www.inflearn.com/course/%EC%8A%A4%ED%94%84%EB%A7%81-%ED%95%B5%EC%8B%AC-%EC%9B%90%EB%A6%AC-%EA%B8%B0%EB%B3%B8%ED%8E%B8/dashboard

profile
๐Ÿง‘๐Ÿปโ€๐Ÿ’ปiOS
post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€