Spring,xml,@Controller,@Autowired,
@RequestMapping,@Service;
,xml:
<context:component-scan base-package="..."/>
:
<mvc:annotation-driven/>
??
Spring,xml,@Controller,@Autowired,
@RequestMapping,@Service;
,xml:
<context:component-scan base-package="..."/>
:
<mvc:annotation-driven/>
??
their roles do not coincide.
The function of context:component-scan
is to scan the corresponding base-package, to scan the classes annotated by @ Component
, @ Controller
, @ Service
, @ Repository
in the corresponding Bean. These Bean provide the most basic support for Spring MVC to register a Bean, in the context.
while < mvc:annotation-driven/ >
provides additional support for MVC. Refer to Spring official document , < mvc:annotation-driven/ >
the main function is to register HandlerMapping
(implemented as DefaultAnnotationHandlerMapping) and HandlerAdapter
(implemented as AnnotationMethodHandlerAdapter). These two Bean provide the ability to forward requests for @ Controllers
(all controllers). There are other features available for MVC:
Please refer to the official documentation for more details.