Spring MVC学习:配置简解

来源:互联网 发布:python网络爬虫 编辑:程序博客网 时间:2024/05/17 02:43

1、<context:annotation-config/>:向Spring容器注册AutowiredAnnotationBeanPostProcessor(@Autowired)、CommonAnnotationBeanPostProcessor(@ Resource 、@ PostConstruct、@ PreDestroy)、PersistenceAnnotationBeanPostProcessor(@PersistenceContext)以及 RequiredAnnotationBeanPostProcessor(@Required) 这 4 个BeanPostProcessor。注意:使用<context:component-scan base-package=”XX.XX”/>后就可以移除<context:annotation-config/>,因为前者包含后者。
2、<mvc:annotation-driven />:向Spring容器注册DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter两个映射和适配器bean,@Controller注解使用的前提配置。
3、<context:component-scan>:扫描到有@Component @Controller@Service等这些注解的类就把这些类注册为bean。
4、<mvc:view-controller path="/" view-name="index"/>:当路径为“/”,默认跳转到index页面。
5、<mvc:default-servlet-handler/>:servlet在找页面时,走的是dispatcherServlet路线,找不到的时候会报404加上这个默认的servlet时候,servlet在找不到的时候会去找静态的内容。
6、<mvc:resources mapping="/images/**" location="/images/" cache-period="31556926"/> :匹配URL /images/**  的URL被当做静态资源,由Spring读出到内存中再响应http。


待续。。。


0 0
原创粉丝点击