美文网首页
SpringBoot(21) — IoC中Bean两种调用方式对

SpringBoot(21) — IoC中Bean两种调用方式对

作者: 奔跑的佩恩 | 来源:发表于2021-08-12 11:21 被阅读0次

前言

在上节中,我们已经将到了@Autowired注解的使用。大家感兴趣的话,可参考以下文章
SpringBoot(20) — @Autowired带参调用
那么。今天让我们来总结下IoCBean不同调用方式的对比。

今天涉及以下知识:

  1. IoC中Bean两种调用方式
  2. SpringBoot项目结构简介
  3. 两种Bean调用方式的不同

一. IoC中Bean两种调用方式

就目前我学习的知识而言。 IoCBean的调用有两种方式:

  • 通过AnnotationConfigApplicationContext构建容器找对象
  • 通过@Autowired注解获取对象

二. SpringBoot 项目结构简介

在讲两种Bean调用方式的不同之前,让我们先来温习下SpringBoot项目架构:
SpringBoot(9) — 项目分层(上)
SpringBoot(10) — 项目分层(下)
由之前文章的介绍,我们可以知道,在一个SpringBoot项目中会涉及到几个重要的注解:

  • @Repository:dao层注解,面对数据库
  • @Service:service层注解,面对业务逻辑层
  • @RestController:controller层注解,给外部提供接口标准

以上涉及到的三个注解由一个共同特点,那就是他们都具备@Component特性。

三. 两种Bean调用方式的不同

在上面我们已经对SpringBoot 项目结构中的三个注解做了简要分析。那么让我们来看看AnnotationConfigApplicationContext@Autowired调用对象的不同。
AnnotationConfigApplicationContext获取对象一般示例为:

相关文章

  • SpringBoot(21) — IoC中Bean两种调用方式对

    前言 在上节中,我们已经将到了@Autowired注解的使用。大家感兴趣的话,可参考以下文章SpringBoot(...

  • Springboot解析spel表达式

    调用springboot解析spel表达式,可以通过表达式调用ioc容器中的bean或者解析自定义的参数 appl...

  • SpringBoot(22) — IoC中Bean的生命周期

    前言 在之前我们已经讲到了IoC中Bean的加载和调用,感兴趣的可参考以下文章SpringBoot(17) — I...

  • SpringBoot(23) — @Conditional检测数

    前言 上节我们讲到了IoC中Bean的生命周期,大家感兴趣的话可参考SpringBoot(22) — IoC中Be...

  • spring国际化

    Springboot 多语spring多语的使用,需要将名称为messageSource的bean放到ioc容器中...

  • SpringIOC

    配置bean class: bean 的全类名,通过反射的方式在IOC容器中创建Bean,所以要求Bean中必须有...

  • IOC容器中bean的生命周期

    Spring的IOC容器为我们提供了一系列干预bean生命周期的扩展点。 初始化bean 调用IOC容器中的Bea...

  • Java Spring-配置Bean

    配置bean,class:bean的全类名,通过反射的方式在IOC容器中创建Bean,所以要求Bean中必须有无参...

  • Java注解方式

    先通过xml的方式将User这个Bean注入到IOC容器中,当使用@Bean创建UserHolder这个Bean时...

  • Spring AOP编程实战

    Spring框架的IOC功能之注解的方式 Spring框架的IOC之注解方式的快速入门 Spring框架中Bean...

网友评论

      本文标题:SpringBoot(21) — IoC中Bean两种调用方式对

      本文链接:https://www.haomeiwen.com/subject/suxlbltx.html