-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
412c498
commit c1f628b
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/test/java/hello/core/beanfind/ApplicationContextInfoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package hello.core.beanfind; | ||
|
||
import hello.core.order.AppConfig; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.config.BeanDefinition; | ||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
|
||
public class ApplicationContextInfoTest { | ||
|
||
AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(AppConfig.class); | ||
|
||
@Test | ||
@DisplayName("모든 Bean 출력") | ||
void findAllBean() { | ||
String[] beanDefinitionNames = ac.getBeanDefinitionNames(); | ||
for (String beanDefinitionName : beanDefinitionNames) { | ||
Object bean = ac.getBean(beanDefinitionName); | ||
System.out.println("name = " + beanDefinitionName + " object = " + bean); // bean 이 key, soutv 부분이 value | ||
} | ||
} | ||
@Test | ||
@DisplayName("Application Bean 출력") // ROLE_APPLICATION: 직접 등록한 애플리케이션 Bean | ||
void findApplicationBean() { | ||
String[] beanDefinitionNames = ac.getBeanDefinitionNames(); | ||
for (String beanDefinitionName : beanDefinitionNames) { | ||
BeanDefinition beanDefinition = ac.getBeanDefinition(beanDefinitionName); | ||
|
||
// cf) ROLE_INFRASTRUCTURE: 스프링이 내부에서 사용하는 Bean | ||
if (beanDefinition.getRole() == BeanDefinition.ROLE_APPLICATION) { | ||
Object bean = ac.getBean(beanDefinitionName); | ||
System.out.println("name = " + beanDefinitionName + " object = " + bean); // bean 이 key, soutv 부분이 value | ||
} | ||
} | ||
} | ||
} |