vkdlxj3562
@charliezip
Reviews Written
-
Average Rating
-
Posts
Q&A
๋น ์ด๋ฆ ์ค์ ๊ด๋ จ ์ง๋ฌธ
ํน์ ๋์์ด ๋์ค๊น ์ ์ด๋ด ๋๋ค.์ํ๋์ ์คํ๋ง ํต์ฌ์๋ฆฌ ๊ฐ์๋ฅผ ์ฐธ๊ณ ํ์ฌ ๋น ์ด๋ฆ์ ์กฐํํด ๋ณด์์ต๋๋ค. ๋จผ์ ๋น ์ด๋ฆ ์กฐํํ๋ ํ ์คํธ ์ฝ๋์ ๋๋ค. package hello.thymeleaf.basic; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import static org.junit.jupiter.api.Assertions.*; class BasicControllerTest { AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(BasicController.HelloBean.class); @Test @DisplayName("์ ํ๋ฆฌ์ผ์ด์ ๋น ์ถ๋ ฅํ๊ธฐ") void findApplicationBean() { String[] beanDefinitionNames = ac.getBeanDefinitionNames(); for (String beanDefinitionName : beanDefinitionNames) { BeanDefinition beanDefinition = ac.getBeanDefinition(beanDefinitionName); //Role ROLE_APPLICATION: ์ง์ ๋ฑ๋กํ ์ ํ๋ฆฌ์ผ์ด์ ๋น //Role ROLE_INFRASTRUCTURE: ์คํ๋ง์ด ๋ด๋ถ์์ ์ฌ์ฉํ๋ ๋น if (beanDefinition.getRole() == BeanDefinition.ROLE_APPLICATION) { Object bean = ac.getBean(beanDefinitionName); System.out.println("name = " + beanDefinitionName + " object=" + bean); } } } } ์ฒซ๋ฒ์งธ๋ก, @Component("helloBean") ๋น ์ด๋ฆ์ ์ง์ ํด ์ค ๊ฒฝ์ฐ๋ฅผ ํ ์คํธ ํด๋ณด๊ฒ ์ต๋๋ค. @Component("helloBean") static class HelloBean { public String hello(String data) { return "Hello " + data; } } ์ด ๊ฒฝ์ฐ์๋ (์ฌ์ง)๋น ์ด๋ฆ์ด "helloBean" ์ผ๋ก ์ ๋ฑ๋ก๋์ด ์๋๊ฒ ํ์ธ ๋ฉ๋๋ค. ๋๋ฒ์งธ๋ก, @Component ๋ก ๋น ์ด๋ฆ์ ์ง์ ํด์ฃผ์ง ์์ ๊ฒฝ์ฐ๋ฅผ ํ ์คํธ ํด๋ณด๊ฒ ์ต๋๋ค. @Component static class HelloBean { public String hello(String data) { return "Hello " + data; } } ์ด ๊ฒฝ์ฐ์๋ (์ฌ์ง) ๋น ์ด๋ฆ์ด "basicController.HelloBean" ์ผ๋ก ๋ฑ๋ก๋์ด ์์ต๋๋ค. ๊ทธ๋์ ํน์ ํ์๋ฆฌํ๊ฐ basicController.HelloBean ๋น ์ด๋ฆ์ ์ธ์ํ ๊น ํด๋ณด์์ง๋ง ์ธ์ํ์ง ์๋๋ผ๊ณ ์ ใ ๋ถ์กฑํ์ง๋ง ๋์์ด ๋์ จ์ผ๋ฉด ์ข๊ฒ ์ต๋๋ค.
- 2
- 5
- 466
Q&A
@RequiredArgsConstructor๊ณผ @Qualifier์ง๋ฌธ
ํด๊ฒฐ๋์์ต๋๋ค!! ์น์ ํ ๋ต๋ณ ๊ฐ์ฌ๋๋ฆฝ๋๋ค!!
- 13
- 5
- 5.6K




