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的更多相关文章

  1. Spring的annotation用在set方法上 hibernate的annotation用get方法上

    1.Spring的annotation用在set方法上 2.hibernate的annotation用在get方法上

  2. Spring 配置 Annotation <context:annotation-config> 和 <context:component-scan>标签的诠释及区别

    Spring 开启Annotation <context:annotation-config> 和 <context:component-scan>诠释及区别 <cont ...

  3. spring,spring mvc之所以起作用是因为开启了注解解释器,即spring的annotation on

    spring,spring mvc之所以起作用是因为开启了注解解释器,即spring的annotation on

  4. Spring Enable annotation – writing a custom Enable annotation

    原文地址:https://www.javacodegeeks.com/2015/04/spring-enable-annotation-writing-a-custom-enable-annotati ...

  5. [Spring MVC] - Annotation验证

    使用Spring MVC的Annotation验证可以直接对view model的简单数据验证,注意,这里是简单的,如果model的数据验证需要有一些比较复杂的业务逻辑性在里头,只是使用annotat ...

  6. [Spring] IOC - Annotation

    Spring Annotation使用例子. 与XML配置的例子一样:http://www.cnblogs.com/HD/p/3962541.html Project结构: 配置文件:springCo ...

  7. Spring 开启Annotation <context:annotation-config> 和 <context:component-scan>诠释及区别

    <context:annotation-config> 和 <context:component-scan>的区别 <context:annotation-config& ...

  8. spring3 jsp页面使用<form:form modelAttribute="xxxx" action="xxxx">报错,附连接数据库的spring MVC annotation 案例

    在写一个使用spring3 的form标签的例子时,一直报错,错误信息为:java.lang.IllegalStateException: Neither BindingResult nor plai ...

  9. 实现运行在独立线程池的调度功能,基于Spring和Annotation

    使用Spring的注解(@Scheduled)声明多个调度的时候,由于其默认实现机制,将导致多个调度方法之间相互干扰(简单理解就是调度不按配置的时间点执行). 为了解决该问题尝试了修改线程池大小,但是 ...

  10. (转)Spring开启Annotation<context:annotation-config> 和 <context:component-scan>诠释及区别

    转自:https://www.cnblogs.com/leiOOlei/p/3713989.html <context:annotation-config> 和 <context:c ...

随机推荐

  1. [Ubuntu]清除系统磁盘垃圾

    操作步骤: 1.sudo apt-get autoremove(卸载系统中所有未被使用的依赖关系) 2.sudo apt-get clean(清除所有缓存的包文件) 以上操作绿色无害,对系统无影响.

  2. LR常用函数汇总

    lr_start_transaction为性能分析标记事务的开始 lr_end_transaction为性能分析标记事务的结束 lr_rendezvous在 Vuser 脚本中设置集合点 lr_thi ...

  3. [文章泛读] The varying faces of a program transformation systems (ACM Inroads, 2012)

    Beevi S. Nadera, D. Chitraprasad, and Vinod S. S. Chandra. 2012. The varying faces of a program tran ...

  4. vs和github同步开发步骤

    首先,这是在visual studio中使用.需要了解关于vs同步github必不可少.下载安装破解什么的先完成vs. 1. 然后安装一个vs中使用github的插件.vs自带的下载.这个是下载地址. ...

  5. 怎样将英文版的Eclipse转为中文版的?

    =====>1.打开eclipse储存文件夹 =====>2.在eclipse文件中找到dropins文件 =====>3.把已经下载好的eclipse汉化包复制到dropins中 ...

  6. Tensorflow_入门学习_1

    1.0 TensorFlow graphs Tensorflow是基于graph based computation: 如: a=(b+c)∗(c+2) 可分解为 d=b+c e=c+2 a=d∗e ...

  7. 万事先问『为什么』 what why how

    万事先问『为什么』! 遇到问题时,很多人的行为模式顺序是,先问『做什么』,『怎么做』,他们从来不问『为什么』,他们对根源性问题很模糊. 而聪明人则是先问『为什么』,再去构建『怎么做』,而『做什么』就是 ...

  8. lg、ln的表示方法

    c语言中 函数 log(x) 表示是以e为底的自然对数,即 ln(x) 函数 log10(x) 以10为底的对数,即 lg(x) 以其它数为底的对数用换底公式来表示 log(a)/log(b) 函数 ...

  9. [已解决]gitee初次使用git clone报错

    本文描述的错误按实际出现先后顺序排列,并且附上一些其他可能会出现的问题 错误1: JZKJ@DESKTOP-I7Q9QJ4 MINGW64 ~ $ git clone https://gitee.co ...

  10. 【Qt】2.1 创建对话框

    QDialog是Qt对话框类,可以直接使用这个类来创建对象并显示出来. 要使用一个对话框,就这样子写: #include <QApplication> #include <QDial ...