๋ฐ์ํ
๊ธฐ๋ณธ ์กฐํ
ac.getBean(๋น์ด๋ฆ, ํ์ )
๐ก ์ค๋ฅ ํ ์คํธ๋น์ด ์์ผ๋ฉด NoSuchBeanDefinitionException ์์ธ๊ฐ ๋ฐ์ํ๋ค.
assertThrows๋ฅผ ์ฌ์ฉํ์ฌ ํด๋น ์์ธ๊ฐ ๋ฐ์ ์ ํ ์คํธ ์ฑ๊ณต์ด ๋จ๊ฒ๋ ์ฝ๋๊ฐ ์ง์๋ค.
๋์ผํ ํ์ ์ด ๋๊ฐ ์ด์์ผ ๊ฒฝ์ฐ
๐ก ํน์ ํ์ ๋ชจ๋ ์กฐํํ๊ธฐ ac.getBeansOfType(ํ์ );
์์๊ด๊ณ
- ๋ถ๋ชจ ํ์
(Interface)์ผ๋ก ์กฐํํ๋ฉด, ์์ ํ์
๋ ํจ๊ป ์กฐํ๋๋ค.
- ๊ทธ๋์ ๋ชจ๋ ์๋ฐ ๊ฐ์ฒด์ ์ต๊ณ ๋ถ๋ชจ์ธ Objectํ์ ์ผ๋ก ์กฐํํ๋ฉด, ๋ชจ๋ ์คํ๋ง ๋น์ ์กฐํํ ์ ์๋ค.
ํ์ ์์๋ ์ด๋ฌํ ๋น ์กฐํ๋ฅผ ์ฌ์ฉํ ์ผ์ด ์์ง๋ง, ์์ ์๋ฐ ์ฝ๋๋ฅผ Spring์ผ๋ก ๋ณํ ์ ์ฌ์ฉ๋๋ค.
โป ์ฐธ์กฐ : https://www.inflearn.com/roadmaps/373
๋ฐ์ํ
'๐ Spring > ๐ Spring Boot' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[SpringBoot]๋ค์ํ ์ค์ ์ง์-์๋ฐ ์ฝ๋, xml (0) | 2025.02.24 |
---|---|
[SpringBoot]BeanFactory์ ApplicationContext (0) | 2025.02.24 |
[SpringBoot]์คํ๋ง์ผ๋ก ์ ํ (1) | 2025.02.20 |
[SpringBoot][Maven][RestAPI]MyBatis, JPA์ฌ์ฉํ๊ธฐ (0) | 2025.01.27 |
[SpringBoot][RestAPI]Get/PostMapping(+json) (0) | 2025.01.26 |