스프링 애플리케이션 빈 출력

bbbbbhyun·2024년 3월 7일
0

BeanDefinition.ROLE_INFRASTRUCTURE : 스프링 내부에서 등록한 애플리케이션 빈

    @Test
    @DisplayName("빈 애플리케이션 출력")
    void findApplicationBean() {
        String[] names = ac.getBeanDefinitionNames();

        for (String name : names) {
            Object ob = ac.getBean(name);
            BeanDefinition beanDefinition = ac.getBeanDefinition(name);

            if (beanDefinition.getRole() == BeanDefinition.ROLE_INFRASTRUCTURE) {
                System.out.println("names : " + name + ", beanDefinition : " + ob);
            }

        }
    }

출력 결과 예시

names : appConfig, beanDefinition : hello.core.AppConfig$$SpringCGLIB$$0@15713d56
names : memberService, beanDefinition : hello.core.member.MemberServiceImpl@63f259c3
names : memberRepository, beanDefinition : hello.core.member.MemoryMemberRepository@26ceffa8
names : discountPolicy, beanDefinition : hello.core.discount.FixDiscountPolicy@600b90df
names : orderService, beanDefinition : hello.core.order.OrderServiceImpl@7c8c9a05

BeanDefinition.ROLE_APPLICATION : 직접 등록한 애플리케이션 빈

    @Test
    @DisplayName("빈 애플리케이션 출력")
    void findApplicationBean() {
        String[] names = ac.getBeanDefinitionNames();

        for (String name : names) {
            Object ob = ac.getBean(name);
            BeanDefinition beanDefinition = ac.getBeanDefinition(name);

            if (beanDefinition.getRole() == BeanDefinition.ROLE_APPLICATION) {
                System.out.println("names : " + name + ", beanDefinition : " + ob);
            }

        }
    }

출력 결과 예시

names : org.springframework.context.annotation.internalConfigurationAnnotationProcessor, beanDefinition : org.springframework.context.annotation.ConfigurationClassPostProcessor@15713d56
names : org.springframework.context.annotation.internalAutowiredAnnotationProcessor, beanDefinition : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor@63f259c3
names : org.springframework.context.annotation.internalCommonAnnotationProcessor, beanDefinition : org.springframework.context.annotation.CommonAnnotationBeanPostProcessor@26ceffa8
names : org.springframework.context.event.internalEventListenerProcessor, beanDefinition : org.springframework.context.event.EventListenerMethodProcessor@600b90df
names : org.springframework.context.event.internalEventListenerFactory, beanDefinition : org.springframework.context.event.DefaultEventListenerFactory@7c8c9a05
profile
BackEnd develope

0개의 댓글