spring之Annotation
spring除了提供了@Autowired,还提供了以下几类annotation。
1、@Component, @Repository, @Service, @Controller
@Repository、@Service、@Controller在目前的 Spring 版本中,这 3 个注释和 @Component 是一样的,但是从注释类的命名上,很容易看出这 3 个注释分别和持久层、业务层和控制层(Web 层)相对应。虽然目前这 3 个注释和 @Component 相比没有什么新意,但 Spring 将在以后的版本中为它们添加特殊的功能。所以,如果Web 应用程序采用了经典的三层分层结构的话,最好在持久层、业务层和控制层分别采用
相当于xml中配置的bean,key默认的就是首字母小写的类名
也可以手动指定key,@service("xxx")相当于@service(name="xxx")
2、@scope
相当于xml中配置的scope属性,有五种类型,singleton,prototype,request,session,global session,可参考前面写的spring之scope。
3、@PreDestroy,@PostConstruct
@PostConstruct相当于xml中配置的init-method,@PreDestroy相当于xml中配置的destroy-method。可参考写的spring之生命周期。
配置如下
4、组件扫描配置
在spring中使用注解annotation,就不需要在xml中配置bean了,但是需要配置组件扫描,这样spring就会把注解了这些annotation的类当做一个bean来处理。
back-package="xxx",xxx表示需要扫描的包。
spring之Annotation的更多相关文章
- Spring的annotation用在set方法上 hibernate的annotation用get方法上
1.Spring的annotation用在set方法上 2.hibernate的annotation用在get方法上
- Spring 配置 Annotation <context:annotation-config> 和 <context:component-scan>标签的诠释及区别
Spring 开启Annotation <context:annotation-config> 和 <context:component-scan>诠释及区别 <cont ...
- spring,spring mvc之所以起作用是因为开启了注解解释器,即spring的annotation on
spring,spring mvc之所以起作用是因为开启了注解解释器,即spring的annotation on
- Spring Enable annotation – writing a custom Enable annotation
原文地址:https://www.javacodegeeks.com/2015/04/spring-enable-annotation-writing-a-custom-enable-annotati ...
- [Spring MVC] - Annotation验证
使用Spring MVC的Annotation验证可以直接对view model的简单数据验证,注意,这里是简单的,如果model的数据验证需要有一些比较复杂的业务逻辑性在里头,只是使用annotat ...
- [Spring] IOC - Annotation
Spring Annotation使用例子. 与XML配置的例子一样:http://www.cnblogs.com/HD/p/3962541.html Project结构: 配置文件:springCo ...
- Spring 开启Annotation <context:annotation-config> 和 <context:component-scan>诠释及区别
<context:annotation-config> 和 <context:component-scan>的区别 <context:annotation-config& ...
- spring3 jsp页面使用<form:form modelAttribute="xxxx" action="xxxx">报错,附连接数据库的spring MVC annotation 案例
在写一个使用spring3 的form标签的例子时,一直报错,错误信息为:java.lang.IllegalStateException: Neither BindingResult nor plai ...
- 实现运行在独立线程池的调度功能,基于Spring和Annotation
使用Spring的注解(@Scheduled)声明多个调度的时候,由于其默认实现机制,将导致多个调度方法之间相互干扰(简单理解就是调度不按配置的时间点执行). 为了解决该问题尝试了修改线程池大小,但是 ...
- (转)Spring开启Annotation<context:annotation-config> 和 <context:component-scan>诠释及区别
转自:https://www.cnblogs.com/leiOOlei/p/3713989.html <context:annotation-config> 和 <context:c ...
随机推荐
- C# 一维数组 二位数组 多维数组
什么是数组? 数组是一组变量,就是把一些变量串在一起,放在一块. 数组的作用? 假设有一堆变量,每个变量都有一些程序,那么这堆程序放在一起 程序就会混乱,处理起来有些麻烦,那么数组就是把这些变量放在 ...
- RunTests.sh && RunIPhoneSecurityd.sh
https://github.com/gh-unit/gh-unit/blob/master/Scripts/RunTests.sh #!/bin/sh # If we aren't ru ...
- CSS-学习笔记四
1.*用于匹配任何的标记 2.>用于指定父子节点关系 3.E+F毗邻元素选择器,匹配所以紧随E元素之后的同级元素F 4.E~F匹配所以E元素之后的同级元素F 5.名称[表达式] [att=val ...
- codevs 1742 爬楼梯(水题日常)
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 小明家外面有一个长长的楼梯,共N阶.小明的腿很长,一次能跨过一或两阶.有一天,他 ...
- (十)maven之排除冲突jar包
排除冲突jar包 jar包冲突 <dependencies> <dependency> <groupId>org.springframework</group ...
- 算法马拉松13 A-E解题报告
A题意(取余最长路): 佳佳有一个n*m的带权矩阵,她想从(1,1)出发走到(n,m)且只能往右往下移动,她能得到的娱乐值为所经过的位置的权的总和. 有一天,她被下了恶毒的诅咒,这个诅咒的作用是将她的 ...
- Android(java)学习笔记145:Handler消息机制的原理和实现
联合学习 Android 异步消息处理机制 让你深入理解 Looper.Handler.Message三者关系 1. 首先我们通过一个实例案例来引出一个异常: (1)布局文件activity_m ...
- oracle中group by的高级用法
简单的group by用法 select c1,sum(c2) from t1 where t1<>'test' group by c1 having sum(c2)>100; ro ...
- Bootstrap 基本按钮
本章将通过实例讲解如何使用Bootstrap按钮,任何带有class.btn的元素都会继承圆角灰色默认按钮样式,但Bootstrap提供了一些选项来定义按钮的样式. 实例 <!DOCTYPE h ...
- shell脚本,提示用户输入一个用户名,如果存在;显示用户UID和SHELL信息;否则,则显示无此用户;显示完成之后,提示用户再次输入;如果是quit则退出;
[root@localhost wyb]# cat tishiuser.sh #!/bin/bash #提示用户输入一个用户名,如果存在:显示用户UID和SHELL信息:否则, #则显示无此用户:显示 ...