springMVC context:component-scan
时间: 2024-01-18 09:04:30 浏览: 43
The <context:component-scan> element in Spring MVC is used to scan the classpath for annotated components (such as controllers, services, repositories, and configuration classes) and automatically register them with the Spring application context.
This element defines a base package to start scanning for annotated components. It can also be used to exclude certain packages or classes from scanning.
For example, the following XML configuration scans the com.example package for annotated components:
<context:component-scan base-package="com.example"/>
This element is often used in conjunction with other Spring MVC configuration elements, such as <mvc:annotation-driven> and <bean> definitions.