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. 设置office首字母不变大小的手段

    选项->校对—〉自动更正选项->“自动更正”页,句首字母大写,取消就行了

  2. License开源许可协议

    开源许可协议 License是软件的授权许可,表述了你获得代码后拥有的权利,可以对别人的作品进行何种操作,何种操作又是被禁止的. 开源许可证种类 Open Source Initiative http ...

  3. cgi_and_fastcgi

    CGI 来自维基百科 In computing, Common Gateway Interface (CGI) offers a standard protocol for web servers t ...

  4. 手把手教你打造一个 Mac 风格的 Windows10(手动滑稽)

    Mark  https://www.sqlsec.com/2018/04/winmac.html 大佬写得很好,资瓷!! MyDock可能不是最新的,给出官方维护的网盘:https://pan.bai ...

  5. 历史管理 onhashchange

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. PyCharm如何配置断点调试功能

    1. 点击菜单 PyCharm -> Preferences.. 2. 在左侧菜单栏找到Project:Django - > Project Interpreter 并点击配置 Proje ...

  7. hihoCoder第一周---最长回文子串(1032)

    其实这就是mancher算法的板子题,贴个代码好了. 思想请见我的另一篇博客: https://blog.csdn.net/qq_41090676/article/details/86768361 # ...

  8. 【数学 裴蜀定理】bzoj2257: [Jsoi2009]瓶子和燃料

    使gcd最大的trick Description jyy就一直想着尽快回地球,可惜他飞船的燃料不够了. 有一天他又去向火星人要燃料,这次火星人答应了,要jyy用飞船上的瓶子来换.jyy的飞船上共有 N ...

  9. 【DB_MySQL】 limit——取查询结果的子集

    语法:select * from student limit beginIndex,length; 这里结果集的下标同数组一样从0开始,beginIndex表示起始位置,length表示从beginI ...

  10. Mysql 5.7在Linux上部署及远程访问

    序言:最近要和伙伴一起组队,做.NET Core项目.所以自己就租了一个阿里云服务器,并且装了Linux和MySQL.这里面我的Linux是CentOs 7. 第一步 添加Mysql Yum库 这里面 ...