![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicmbw5SNyQTY1YWO1MWM4gDMxIWY4AzY0cDNzMTY4AzY5cDM58CX5d2bs92Yl1iclB3bsVmdlR2LcNWaw9CXt92Yu4GZjlGbh5yYjV3Lc9CX6MHc0RHaiojIsJye.png)
1.mvc:annotation-driven
:确定调用哪个controller的哪个方法来处理当前请求。如果没有回找不到@RequestMapping指定的路径。
2.context:annotation-config
扫描的注解如下:@Autowired,@Resource 、@PostConstruct、@PreDestroy,@PersistenceContext,@Required。
3.context:component-scan
:context:component-scan做了context:annotation-config要做的事情,还额外支持@Component,@Repository,@Service, @Controller @RestController, @ControllerAdvice, and @Configuration 注解。
所以配置context:component-scan就不需要配置context:annotation- config。
<context:component-scan base-package="test.*.controller" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
</context:component-scan>
use-default-filters=“false”,不使用默认过滤器(所有包都不自动扫描),需要
,全部包都扫描,除了标签里面配置的。
<context:component-scan base-package="test.*">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
</context:component-scan>