Spring 框架知识点汇总

1、<context:annotation-config /> 标签

Spring MVC的配置方案,标签会自动注册下列的4个bean:

1) AutowiredAnnotationBeanPostProcessor
对应于使用@AutoWired注解
<bean class="org.springframework.beans.factory.annotation. AutowiredAnnotationBeanPostProcessor "/>

2)CommondAnnotationBeanPostProcessor
对应于使用@Resource、@PostConstruct、@Predestory等注解
<bean class="org.springframework.beans.factory.annotation.CommondAnnotationBeanPostprocessor"/>

3)PersistenceAnnotationBeanPostProcessor
对应于使用@PersistenceContext注解
<bean class="org.springframework.beans.factory.annotation.PersistenceAnnotationBeanPostProcessor"/>

4)RequiredAnnotationBeanPostProcessor
对应于使用@Required注解
<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/>


需要说明的是,<context: component-scan base-package=xxx..xxx.xxx />标签在配置扫描包路径的时候,已经包含了自动注入上述Processor的功能,如果已经配置了包扫描路径的标签,<context annotation-config />可以不在使用。


2、<mvc:annotation-driven />标签

Spring MVC的配置方案,标签会自动注册下列的2个bean

1)DefaultAnnotationHandlerMapping

2) AnnotationMethodHandlerAdapter

对应于使用Controllers注解(Spring MVC控制器Controller部分分发请求所必须的)、数据绑定、@NumberFormatannotation注解、@DateTimeFormat注解、@Valid注解、JAXE读写XML、Jackson读写JSON。


3、 <context:component-scan base-package="xxx.xxx.xxx"></context:component-scan>标签

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

 

@Controller:声明Action组件。用于标注控制层组件(和struts中的action作用类似)

@Service:声明Service组件 。服务层组件,用于标注业务层组件,表示定义一个bean,自动根据bean的类名实例化一个首写字母为小写的bean,例如:MyClass实例化为myClass,如果需要自己改名字则:@Service("mybeanName")。

@Repository 声明持久层组件。用于标注数据访问组件,即DAO组件

@Component   泛指组件, 当不好归类时。(相比以上3个,和@Componet类似)

@RequestMapping("/reqURI")  请求映射

@Resource  用于注入J2EE提供的默认按名称装配,例如:@Resource(name="beanName")

@Autowired 用于注入Srping提供的默认按类型装配

@Transactional( rollbackFor={Exception.class}) 事务管理

@ResponseBody:返回的数据不解析成view,而是直接返回数据类型,如:json或xml。

@Scope("prototype")   设定bean的作用域




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

招财猫_Martin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值