Spring annotation简述

Spring framework 一共有7个主要模块:web

core:管理bean的工厂spring

context:包含JNDI, E-mail, i18n, validate, 调度等功能编程

aop:面向切面编程mvc

dao:模板化JDBC,封装异常结构app

orm:插入hibernate,支持Spring事物及异常层次结构jsp

web:简化请求及其参数绑定到域对象函数

mvc:提供mvc结构策略接口,容纳视图技术ui

web.xml配置:url

首页:spa

<welcome-file-list>

  <welcome-file>index.jsp</welcome-file>

</welcome-file-list>

监听webApplicationContext服务:

<listener>

  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

加载Spring配置文件:

<context-param>

  <param-name>contextConfigLocation</param-name>

  <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>

</context-param>

DispatchServlet拦截全部请求到HanderMapping去映射Controller,Controller返回ViewResolver指定的视图技术的ModelAndView路径:

<servlet>

  <servlet-name>dispatcher<servlet-name>

  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

  <load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

  <servlet-name>dispatcher<servlet-name>

  <url-pattern>*.htm</url-pattern>

</servlet-mapping>

字符集过滤:

 

<context:component-scan base-package="the package have Spring annotation class" />

标识Spring bean:标注在class上

  @Repository:用于数据传输层,监听抛出的异常并封装

  @Service:用于业务层

  @Controller:用于控制层

  @Component:自定义,任何组件

生命周期回调函数:标注在method上

  <context:annotation-config />:配置相应的bean

  @PostConstruct:初始化后执行的method

  @PreDestory:销毁以前执行的method

依赖检查:标注在setXXX()上

  <context:annotation-config />:配置相应的bean

  @Required:检查该setXXX()是否被调用

自动装配:(不详)

  @Resource:

  @Autowired:

  @Qualifier:

bean的声明:标注在class上

  @Configuration:检查此类不能是final,local,必须有一个无参构造的类,并加入IoC

  @Bean:加入IoC容器

相关文章
相关标签/搜索