📌 Spring Core

- 프레임워크의 가장 기본적인 부분

- 컨테이너 기능을 수행하기 위해 의존성 주입 기능을 제공

 

https://docs.spring.io/spring-framework/docs/5.2.25.RELEASE/spring-framework-reference/core.html#spring-core

 

Core Technologies

In the preceding scenario, using @Autowired works well and provides the desired modularity, but determining exactly where the autowired bean definitions are declared is still somewhat ambiguous. For example, as a developer looking at ServiceConfig, how do

docs.spring.io

 

 

 


 

📌 DI (Dependency injection)

 

✅ 개념

  • 외부에서 두 객체 간의 관계를 결정해주는 디자인 패턴으로, 인터페이스를 사이에 둬서 클래스 레벨에서는 의존관계가 고정되지 않도록 하고 런타임 시에 관계를 동적으로 주입하여 유연성을 확보하고 결합도를 낮출 수 있게 해준다.
  • 의존성이란 한 객체가 다른 객체를 사용할 때 의존성이 있다고 한다. 
  • 특정 빈에 임의의 값을 제공하는 것을 의미한다.

 

필요한 이유?

  • 두 객체 간의 관계라는 관심사의 분리
  • 두 객체 간의 결합도를 낮춤
  • 객체의 유연성을 높임
  • 테스트 작성을 용이하게 함

 


 

📌 DI 방법

  • 스프링 방식1 - 태그 이용
    • 생성자 이용 
    • set메서드 이용
  • 스프링 방식2 - namespace의 속성 이용 ⭐⭐  
    • 생성자 이용 (반드시 xmlns:c="http://www.springframework.org/schema/c" 추가)
<bean id="service" class="com.service.UserService" 
c:생성자의변수명="값" c:생성자의변수명-ref="값" />

 

  • set메서드 이용 (  xmlns:p="http://www.springframework.org/schema/p"   추가)
<bean id="service" class="com.service.UserService" 
p:set생성자의변수명="값"   p:set메서드명-ref="값" />

 

'Framework > SPRING FRAMEWORK' 카테고리의 다른 글

03. DI_constructor  (0) 2023.08.28
다양한 의존성 주입 방법 (DI)  (0) 2023.08.28
ApplicationContext 계층구조  (0) 2023.08.28
02. 빈 얻기  (0) 2023.08.26
01. 빈 생성_prefix  (0) 2023.08.26
xoo | 수진