springboot整合Redis _MQ

本文详细介绍了如何在SpringBoot项目中整合Redis作为消息队列(MQ),包括引入相关jar包,配置redis.properties文件,编写RedisConfig配置类,以及创建测试练习类进行实践操作。
摘要由CSDN通过智能技术生成

springboot整合Redis

1、引入jar包
		<!--spring整合redis -->
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-redis</artifactId>
        </dependency>
2、redis.properties文件
# 配置单台Redis
redis.host=192.168.126.129
redis.port=6379
3、RedisConfig配置类
package com.jt.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import redis.clients.jedis.Jedis;

@Configuration  //标识该类为一个配置类
@PropertySource("classpath:/properties/redis.properties")
public class RedisConfig {
   

    @Value("${redis.host}")
    private String host;
    @Value("${redis.port}")
    private Integer port;

    @Bean   //将该方法交给spring进行管理
    public Jedis jedis(){
   
        //数据不能写死,通过配置文件来获取
        return new Jedis(host,port);
    }

}

4、测试练习类
package com.jt.test;


import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import redis.clients.jedis.Jedis;
import redis
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值