Spring Boot 自动装配的原理

本文探讨了Spring Boot自动装配的原理,包括通过@EnableAutoConfiguration注解的启用,AutoConfigurationImportSelector的角色以及自动装配的实现流程。核心流程涉及配置类的导入、ImportSelector的选择性批量装配以及条件筛选的配置类装配。
摘要由CSDN通过智能技术生成

1. 自动装配的原理

自动装配字面意思理解就是将Bean自动装配到IOC容器中,自动装配是Spring Boot的核心功能。我们可以通过Spring Boot整合redis的例子了解自动装配。

  • 引入依赖:
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
  • 在application.properties中配置redis的数据源参数:
spring.redis.host = 127.0.0.1
spring.redis.port = 6379
  • 在HelloServer中使用RedisTemplate实现对redis的操作:
@Service
public class HelloServer {
   

    @Autowired
    private RedisTemplate<String,String> redisTemplate
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值