: ๊ฐ์ฒด์ ์์ฑ๋ถํฐ ์๋ช ์ฃผ๊ธฐ ๊ด๋ฆฌ๊น์ง ์ ํ๋ฆฌ์ผ์ด์ ์ ํ๋ฆ์ ์คํ๋ง ํ๋ ์์ํฌ๊ฐ ๊ด๋ฆฌ
๊ฐ๋ฐ์์ ์ญํ ์ด ์ค์ด๋ค์ด ๋น์ฆ๋์ค ๋ก์ง์ ์ง์คํ ์ ์๊ณ ,
์ฝ๋์ ๊ฒฐํฉ๋๋ฅผ ๋ฎ์ถ๊ณ ์ ์ฐ์ฑ์ ๋์ผ ์ ์์.
: ๊ฐ์ฒด ๊ฐ์ ์์กด์ฑ์ ์ธ๋ถ์์ ์ฃผ์ ํด์ฃผ๋ ๊ฐ๋
๊ฐ์ฒด ๊ฐ์ ๊ฒฐํฉ๋๋ฅผ ๋ฎ์ถ๊ณ , ์ฝ๋์ ์ ์ฐ์ฑ๊ณผ ํ ์คํธ ์ฉ์ด์ฑ์ ๋์ผ ์ ์์

๐ What is POJO?
= IoC Container
ApplicationContext ์ธํฐํ์ด์ค๋ฅผ ํตํด ๊ตฌํ๋จpublic class MyClass {
private InjectionBean injectionBean;
@Autowired
public ConstructorInjection(InjectionBean injectionBean) {
this.injectionBean = injectionBean;
}
}
final ๋ถ์ผ ์ ์์public class MyClass {
private InjectionBean injectionBean;
@Autowired
public void setInjectionBean(InjectionBean injectionBean) {
this.injectionBean = injectionBean;
}
}
๐ Constructor-based or setter-based DI?
Since you can mix constructor-based and setter-based DI, it is a good rule of thumb to use constructors for mandatory dependencies and setter methods or configuration methods for optional dependencies. Note that use of the @Autowired annotation on a setter method can be used to make the property be a required dependency; however, constructor injection with programmatic validation of arguments is preferable.
The Spring team generally advocates constructor injection, as it lets you implement application components as immutable objects and ensures that required dependencies are not null. Furthermore, constructor-injected components are always returned to the client (calling) code in a fully initialized state. As a side note, a large number of constructor arguments is a bad code smell, implying that the class likely has too many responsibilities and should be refactored to better address proper separation of concerns.
โก๏ธ ์ํฉ์ ๋ฐ๋ผ ๋ค๋ฅธ ๋ฐฉ์ ์ฑํ
spring ํ์ ์์ฑ์ ์ฃผ์ ๋ฐฉ์ ์ง์ง
๊ทธ ์ด์ ๋, ์ ํ๋ฆฌ์ผ์ด์ ๊ตฌ์ฑ ์์๋ฅผ ๋ถ๋ณ ๊ฐ์ฒด๋ก ๊ตฌํ ๊ฐ๋ฅํ๊ณ ํ์ ์ข ์์ฑ์ด null์ด ์๋๋๋ก ๋ณด์ฅํจ์ ๋ฆฌํ์๋ฉด
ํ์ ์์กด์ฑ์๋ ์์ฑ์ ์ฃผ์
์ ํ ์์กด์ฑ์๋ ์ธํฐ ์ฃผ์ ์ฌ์ฉ
public class MyClass {
@Autowired
private InjectionBean injectionBean;
}
Mock ๊ฐ์ฒด ์ฃผ์
์ด๋ ค์https://edu.nextstep.camp/s/OiPrZU5t/ls/A3P44ALq
https://f-lab.kr/insight/core-of-spring-framework-dependency-injection-and-ioc-container?gad_source=1&gclid=CjwKCAjwhIS0BhBqEiwADAUhc-SxqhdB4uq3tEbb2gaHzbJH-t0TBTjpILuKLFnVq5fG3C8guawG8hoC1IQQAvD_BwE
https://docs.spring.io/spring-framework/reference/core/beans/dependencies/factory-collaborators.html
https://spring.io/blog/2016/03/04/core-container-refinements-in-spring-framework-4-3