1.@controller 控制器(注入服务)

2.@service 业务(注入dao)

3.@repository dao(实现dao访问)

4.@component (把普通pojo实例化到spring容器中,相当于配置文件中的<bean id="" class=""/>)

5.@Component,@Service,@Controller,@Repository注解的类,并把这些类纳入进spring容器中管理。 

@Service
public class UserServiceImpl implements UserService { } @Repository
public class UserDaoImpl implements UserDao { }

6.<context:annotation-config />

这样就可以使用@ Resource 、@ PostConstruct、@ PreDestroy、@PersistenceContext、@Autowired、@Required等注解了,就可以实现自动注入

7.<context:component-scan base-package="com.**.impl"/>

Spring给我们提供了context:annotation-config 的简化的配置方式,自动帮助你完成声明,并且还自动搜索@Component , @Controller , @Service , @Repository等标注的类。

context:component-scan除了具有context:annotation-config的功能之外,context:component-scan还可以在指定的package下扫描以及注册javabean 。还具有自动将带有@component,@service,@Repository等注解的对象注册到spring容器中的功能。

因此当使用 context:component-scan 后,就可以将 context:annotation-config移除。

8.spring ioc控制反转

<--spring容器控制对象资源属性-->
<bean id="batchNo"
class="com.common.utils.IdGenerator">
<constructor-arg name="datacenterId"
value="${server.datacenterId}"></constructor-arg> --私有成员变量
<constructor-arg name="workerId"
value="${server.workerId}"></constructor-arg>
</bean>
<--spring依赖注入对象--> 
@Autowired
@Qualifier("batchNo")
private IdGenerator idGenerator;

相当于使用@Component("")

spring中@Component注解的更多相关文章

  1. Spring中@Component注解,@Controller注解详解

    在使用Spring的过程中,为了避免大量使用Bean注入的Xml配置文件,我们会采用Spring提供的自动扫描注入的方式,只需要添加几行自动注入的的配置,便可以完成 Service层,Controll ...

  2. Spring中@Component注解,@Controller注解详解

    在使用Spring的过程中,为了避免大量使用Bean注入的Xml配置文件,我们会采用Spring提供的自动扫描注入的方式,只需要添加几行自动注入的的配置,便可以完成 Service层,Controll ...

  3. Spring Boot@Component注解下的类无法@Autowired的问题

    title: Spring Boot@Component注解下的类无法@Autowired的问题 date: 2019-06-26 08:30:03 categories: Spring Boot t ...

  4. Spring中常用注解的介绍

    spring中使用注解时配置文件的写法: <?xml version="1.0" encoding="UTF-8"?> <span style ...

  5. Spring中异步注解@Async的使用、原理及使用时可能导致的问题

    前言 其实最近都在研究事务相关的内容,之所以写这么一篇文章是因为前面写了一篇关于循环依赖的文章: <面试必杀技,讲一讲Spring中的循环依赖> 然后,很多同学碰到了下面这个问题,添加了S ...

  6. Spring中@Import注解的使用

    Spring中@Import注解的使用 @Import注解算是SpringBoot自动配置原理中一个很重要的注解 认识@Import注解 先看一下源码 @Target(ElementType.TYPE ...

  7. Spring中常用注解

    1.@Component 创建类对象,相当于配置<bean/> 2.@Service @Service与@Component功能相同,写在ServiceImpl类上 3.@Reposito ...

  8. 【进阶】Spring中的注解与反射

    [进阶]Spring中的注解与反射 目录 [进阶]Spring中的注解与反射 前言 一.内置(常用)注解 1.1@Overrode 1.2@RequestMapping 1.3@RequestBody ...

  9. Spring中@Autowired注解、@Resource注解的区别 (zz)

    Spring中@Autowired注解.@Resource注解的区别 Spring不但支持自己定义的@Autowired注解,还支持几个由JSR-250规范定义的注解,它们分别是@Resource.@ ...

随机推荐

  1. js中迭代方法

    基础遍历数组:            for()            for( in )             for(var i = 0;i<arr.length;i++){       ...

  2. 训练20191005 2017-2018 ACM-ICPC Asia East Continent League Final

    A 签到 M 签到 K 读懂后签到 L 博弈论 [引理]出现SXXS结构时后手必胜. 很容易发现n为奇数时后手不可能胜利,n为偶数时先手不可能胜利.n≤6时一定平局,n≥7时先手有可能胜利,n≥16时 ...

  3. python使用临时文件

    # 需求 # 某项目中,我们从传感器中采集数据,没采集1G数据后,做数据分析,最终只保存分析结果 # 这样很大的临时文件如果常驻在内存,将消耗大量地内存资源,我们可以使用临时文件储存(外部储存) # ...

  4. OpenGL 3D拾取文章(转)

    参考文章 深入探索3D拾取技术 OpenGL 3D拾取 射线和三角形的相交检测(ray triangle intersection test) 3D拾取的方法有两种 1.基于几何计算的射线-三角形相交 ...

  5. nginx location匹配及rewrite规则

    location匹配规则 1. 实例 server{ location = \ { [配置A] } location / { [配置B] } location = /images/ { [配置C] } ...

  6. I/O多路复用select/poll/epoll

    前言 早期操作系统通常将进程中可创建的线程数限制在一个较低的阈值,大约几百个.因此, 操作系统会提供一些高效的方法来实现多路IO,例如Unix的select和poll.现代操作系统中,线程数已经得到了 ...

  7. EF简单增删改查

    第一步:创建上下文对象 using(var db = new Entities()) { //数据操作 } 新增 UserInfo user = new UserInfo() { UserName = ...

  8. 19年7月份面试7家公司,整理的java面试题(答案自行百度解决,也是个学习的过程)

    Dubbo与注册中心Zookeeper了解多少ConcurrentHashMap的原理 集合 HashMap 和 HashTable和ConcurrentHashMap的原理以及区别HashMap初始 ...

  9. 联想小新潮怎么修改fn热键以及怎么进入bios状态

    联想小新潮怎么修改fn热键 http://www.ylmfwin100.com/ylmfnew/11129.html  怎么进入bios状态  https://zhidao.baidu.com/que ...

  10. 安装apache ActiveMQ

    笔者环境 操作系统centos 6.9 java jdk 1.8 activemq版本 5.15.9 a)安装activemq需要jdk 环境,这里使用的是 jdk 1.8 yum安装jdk比较简单, ...