SpringMVC-DispatcherServlet配置(Spring-servlet.xml)

Spring-servlet.xml

  1. 扫描指定的包中的类上的注解,常用的注解有:

    @Controller 声明Action组件
    @Service    声明Service组件    @Service("myMovieLister") 
    @Repository 声明Dao组件
    @Component   泛指组件, 当不好归类时. 
    @RequestMapping("/menu")  请求映射
    @Resource  用于注入,( j2ee提供的 ) 默认按名称装配,@Resource(name="beanName") 
    @Autowired 用于注入,(srping提供的) 默认按类型装配 
    @Transactional( rollbackFor={Exception.class}) 事务管理
    @ResponseBody
    @Scope("prototype")   设定bean的作用域

  2. 是一种简写形式,完全可以手动配置替代这种简写形式,简写形式可以让初学都快速应用默认配置方案。 会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,是spring MVC为@Controllers分发请求所必须的。
  3. 视图解析类,使用普通bean的配置方式:
    复制代码
    1 
    2 
    3 
    4 
    5 
    复制代码
  4. 添加静态资源访问的支持:
    1 

    匹配URL  /resources/**  的URL被当做静态资源,由Spring读出到内存中再响应http。

    或直接使用默认的Servlet来响应静态文件。


示例:

复制代码
 1 
 2 
14     
15     
16         
17             
18             
19         
20     
21  
22 
复制代码

 


God, Grant me the SERENITY, to accept the things I cannot change, COURAGE to change the things I can, and the WISDOM to know the difference.

你可能感兴趣的:(SpringMVC-DispatcherServlet配置(Spring-servlet.xml))