[Spring]IoC, DI

cheolhakja·2022년 5월 9일
0

spring

목록 보기
6/9

The initialisation of ApplicationEventPublisher doesn't happen OR will remain null, if you have created the CustomeEvent without the help of Bean (like CustomEvent event = new CustomEvent().

CustomEvent를 빈으로 등록한 뒤 스프링 컨테이너에 의해 주입받지 않으면

Instead, declare the CustomEvent as bean in your configuration (Spring) and get the CustomEvent using application context.


인터페이스와 구현체를 빈으로 등록하고 주입받는 경우

How does spring know which polymorphic type to use.

As long as there is only a single implementation of the interface and that implementation is annotated with @Component with Spring's component scan enabled, Spring framework can find out the (interface, implementation) pair. If component scan is not enabled, then you have to define the bean explicitly in your application-config.xml (or equivalent spring configuration file).

Do I need @Qualifier or @Resource?

Once you have more than one implementation, then you need to qualify each of them and during auto-wiring, you would need to use the @Qualifier annotation to inject the right implementation, along with @Autowired annotation. If you are using @Resource (J2EE semantics), then you should specify the bean name using the name attribute of this annotation.

0개의 댓글

관련 채용 정보