Câu hỏi phỏng vấn Spring
Câu hỏi

Explain the difference between <context:ann...

Câu trả lời

The difference between <context:annotation-config> and <context:component-scan> in Spring MVC revolves primarily around their roles in bean registration and annotation processing within the Spring container.

<context:annotation-config>

The <context:annotation-config> tag is used specifically to activate annotations on beans that have already been registered in the Spring application context. This tag does not itself register any beans; instead, it is used to enhance beans that are already managed by the Spring container. It processes annotations like @Autowired, @Resource, @PostConstruct, @PreDestroy, and @Required on existing beans, regardless of how these beans were registered (either through XML configuration or through component scanning)[2][3].

<context:component-scan>

On the other hand, <context:component-scan> is a more comprehensive directive that not only activates annotations but also automatically detects and registers bean definitions. When you use <context:component-scan>, Spring scans the specified packages and automatically registers beans for any classes annotated with stereotype annotations such as @Component, @Service, @Repository, @Controller, etc. This tag effectively subsumes the functionality of <context:annotation-config> because it not only detects and registers beans but also activates annotations on them[2][3][5].

Key Differences

  1. Bean Registration: <context:component-scan> registers beans automatically from the specified packages based on annotations, whereas <context:annotation-config> only processes annotations on already registered beans.

  2. Scope of Functionality: <context:component-scan> includes the functionality of <context:annotation-config> (activat...

expert

expert

Gợi ý câu hỏi phỏng vấn

middle

How would you relate Spring MVC Framework to MVC architecture?

senior

What bean scopes does Spring support? Explain them.

middle

What is the typical Bean life cycle in Spring Bean Factory Container?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào