Spring Boot 缓存优化Redis 实战指南

 更新时间:2026年03月16日 16:55:52   作者:码客日记  
本文介绍了如何在SpringBoot项目中集成Redis缓存,以优化性能并提高用户体验,通过实战,读者可以快速掌握Redis缓存的集成方法,并在实际项目中应用,解决数据量大的性能瓶颈,感兴趣的朋友跟随小编一起看看吧

当你的Spring Boot项目逐步落地、用户量攀升、数据量不断增大后,你会发现一个明显的问题:频繁查询数据库会导致接口响应变慢、数据库压力剧增,甚至出现卡顿、超时的情况——这既是项目发展的信号,也是需要优化的节点。缓存作为提升项目性能的核心手段,能有效减少数据库查询压力,让接口响应速度翻倍,同时让你的项目显得更专业、更具竞争力。本文承接项目数据量大后的优化需求,手把手实战Spring Boot集成Redis缓存,从环境搭建、核心注解使用,到热点数据缓存的真实案例,代码可直接复制复用,帮你快速落地缓存优化,轻松解决数据量大带来的性能瓶颈。

一、前置准备:明确缓存核心与环境搭建

缓存的核心逻辑:将频繁查询、不常变化的数据(热点数据)存储在Redis(内存数据库)中,后续查询时优先从Redis获取,避免频繁访问MySQL等关系型数据库,从而提升响应速度、降低数据库压力。本次实战基于Spring Boot + Redis + MyBatis-Plus,贴合真实项目架构,聚焦核心缓存功能落地。

1.1 环境准备

  • Redis环境:本地安装Redis(Windows/Linux均可),确保Redis服务正常启动(默认端口6379),无密码或记住密码(后续配置使用);
  • 项目基础:已搭建Spring Boot项目,包含MyBatis-Plus(用于数据库操作)、Web依赖(接口开发),确保数据库连接正常。

1.2 Maven 核心依赖

Spring Boot提供了Redis缓存的自动配置依赖,无需复杂配置,引入以下依赖即可快速集成Redis缓存:

<!-- Spring Boot Web 核心依赖 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Spring Boot Redis 缓存依赖(核心,自动配置) -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- Spring Boot 缓存抽象依赖(提供缓存注解支持) -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<!-- MyBatis-Plus 依赖(操作数据库) -->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.5.3.1</version>
</dependency>
<!-- MySQL 驱动 -->
<dependency>
    <groupId>com.mysql</groupId>
    <artifactId>mysql-connector-j</artifactId>
    <scope>runtime</scope>
</dependency>
<!-- lombok 简化代码 -->
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <optional>true</optional>
</dependency>
<!-- 可选:Redis 连接池依赖(提升Redis连接性能) -->
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-pool2</artifactId>
</dependency>

1.3 核心配置(application.yml)

配置Redis连接信息、缓存相关参数,以及缓存序列化方式(避免Redis中存储的中文乱码、对象无法反序列化),适配项目生产环境需求:

spring:
  # 数据库配置(替换为自己的数据库信息)
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/springboot_redis?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
    username: root
    password: 123456
  # Redis 核心配置
  redis:
    host: localhost # Redis服务器地址(本地为localhost,远程为服务器IP)
    port: 6379 # Redis默认端口
    password: # Redis密码(无密码则留空)
    database: 0 # 操作的Redis数据库(默认0号库)
    # Redis连接池配置(提升连接性能,推荐配置)
    lettuce:
      pool:
        max-active: 16 # 最大连接数
        max-idle: 8 # 最大空闲连接
        min-idle: 4 # 最小空闲连接
        max-wait: 1000 # 最大等待时间(毫秒)
  # 缓存配置(开启缓存,指定缓存类型为Redis)
  cache:
    type: redis # 缓存类型:Redis(默认是Simple,本地内存,不适用于生产)
    redis:
      time-to-live: 3600000 # 缓存默认过期时间(1小时,单位:毫秒)
      cache-null-values: false # 是否缓存null值(避免缓存穿透,根据需求调整)
      key-prefix: springboot:cache: # 缓存key前缀(避免与其他Redis数据冲突)
      use-key-prefix: true # 启用key前缀
# MyBatis-Plus 配置(打印SQL,便于调试缓存效果)
mybatis-plus:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  mapper-locations: classpath:mybatis/mapper/**/*.xml
  type-aliases-package: com.example.demo.entity

1.4 开启缓存功能(核心注解)

在Spring Boot启动类上添加@EnableCaching注解,开启缓存功能,一行代码即可完成,简洁高效,是后续使用缓存注解的前提:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
/**
 * 启动类:开启缓存功能(@EnableCaching)
 */
@SpringBootApplication
@EnableCaching // 开启缓存功能,必须添加,否则缓存注解无效
public class SpringBootRedisCacheApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringBootRedisCacheApplication.class, args);
    }
}

关键注意点:1. @EnableCaching必须添加在启动类或配置类上,否则@Cacheable、@CacheEvict等注解无法生效;2. 配置Redis缓存序列化方式(后续会补充),避免出现中文乱码、对象反序列化失败的问题;3. 确保Redis服务正常启动,否则项目启动会报错。

1.5 补充:Redis缓存序列化配置(可选但推荐)

Spring Boot默认的Redis缓存序列化方式会导致缓存的对象转为二进制,无法直接查看,且中文会乱码。自定义序列化配置,将对象序列化为JSON格式,便于调试和查看,提升开发效率:

import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import java.time.Duration;
/**
 * Redis缓存序列化配置(将对象序列化为JSON格式)
 */
@Configuration
@EnableCaching
public class RedisCacheConfig {
    @Bean
    public RedisCacheManager redisCacheManager(RedisConnectionFactory connectionFactory) {
        // 1. 配置缓存序列化方式
        RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
                // 设置缓存过期时间(全局默认,可在注解中单独设置)
                .entryTtl(Duration.ofHours(1))
                // key序列化:String格式
                .serializeKeysWith(RedisSerializationContext.SerializationPair
                        .fromSerializer(new StringRedisSerializer()))
                // value序列化:JSON格式(支持对象序列化)
                .serializeValuesWith(RedisSerializationContext.SerializationPair
                        .fromSerializer(new GenericJackson2JsonRedisSerializer()))
                // 不缓存null值
                .disableCachingNullValues()
                // 启用key前缀
                .prefixCacheNameWith("springboot:cache:");
        // 2. 创建缓存管理器并返回
        return RedisCacheManager.builder(connectionFactory)
                .cacheDefaults(config)
                .build();
    }
}

二、核心实战一:Redis 集成测试(确保环境可用)

集成Redis后,先编写简单的测试接口,验证Redis连接正常、缓存功能可正常使用,为后续缓存注解和案例落地打下基础:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * Redis 集成测试控制器
 */
@RestController
@RequestMapping("/redis/test")
public class RedisTestController {
    // 注入Redis模板(StringRedisTemplate用于操作字符串,RedisTemplate用于操作对象)
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    /**
     * 测试Redis存储字符串
     */
    @GetMapping("/set")
    public String setRedis(@RequestParam String key, @RequestParam String value) {
        // 存储数据到Redis
        stringRedisTemplate.opsForValue().set(key, value);
        return "Redis存储成功,key:" + key + ",value:" + value;
    }
    /**
     * 测试Redis获取字符串
     */
    @GetMapping("/get")
    public String getRedis(@RequestParam String key) {
        // 从Redis获取数据
        String value = stringRedisTemplate.opsForValue().get(key);
        return "Redis获取结果,key:" + key + ",value:" + (value == null ? "无此key" : value);
    }
}

测试步骤:

  • 访问接口:http://localhost:8080/redis/test/set?key=test&value=redis-cache,返回存储成功;
  • 访问接口:http://localhost:8080/redis/test/get?key=test,返回获取到的value;
  • 打开Redis客户端(如Redis Desktop Manager),可看到存储的key-value(JSON格式,无乱码),说明Redis集成成功。

三、核心实战二:常用缓存注解(@Cacheable、@CacheEvict)

Spring Boot缓存抽象提供了便捷的注解,无需手动编写Redis操作代码,仅通过注解即可实现缓存的增、删、查,核心常用注解为@Cacheable(查询缓存)和@CacheEvict(删除缓存),覆盖大多数缓存场景。

3.1 @Cacheable:查询缓存(核心注解)

作用:在方法执行前,先检查Redis中是否有对应缓存;若有,直接返回缓存数据,不执行方法;若没有,执行方法,将方法返回结果存入Redis,后续查询直接复用缓存。

核心参数(常用):

  • value/cacheNames:缓存名称(必填),用于区分不同缓存模块(如用户缓存、商品缓存);
  • key:缓存的key(可选),支持SpEL表达式,自定义缓存key,避免key冲突;
  • unless:条件表达式(可选),满足条件时不缓存(如返回值为null时不缓存);
  • expire:缓存过期时间(可选),优先级高于全局配置,单位:秒。
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.entity.SysUser;
import com.example.demo.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * 缓存注解测试控制器(用户模块)
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private SysUserService sysUserService;
    /**
     * 示例1:根据用户ID查询用户(缓存key为用户ID)
     * @Cacheable:查询缓存,缓存名称为user,key为用户ID
     */
    @Cacheable(value = "user", key = "#userId", unless = "#result == null")
    @GetMapping("/{userId}")
    public SysUser getUserById(@PathVariable Long userId) {
        // 第一次查询:无缓存,执行方法,查询数据库,存入缓存
        // 第二次查询:有缓存,直接返回缓存数据,不执行该方法(不打印SQL)
        System.out.println("执行数据库查询:根据ID查询用户,ID=" + userId);
        return sysUserService.getById(userId);
    }
    /**
     * 示例2:根据用户名查询用户(自定义缓存key,添加过期时间)
     * key:拼接缓存名称和用户名,避免key冲突;expire:缓存10分钟
     */
    @Cacheable(value = "user", key = "'username:'+#username", expire = 600)
    @GetMapping("/username/{username}")
    public SysUser getUserByUsername(@PathVariable String username) {
        System.out.println("执行数据库查询:根据用户名查询用户,用户名=" + username);
        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", username);
        return sysUserService.getOne(queryWrapper);
    }
}

测试效果:

  • 第一次访问http://localhost:8080/user/1,控制台打印SQL(执行数据库查询),Redis中新增缓存(key:springboot:cache:user::1);
  • 第二次访问同一个接口,控制台不打印SQL(不执行数据库查询),直接返回缓存数据,接口响应速度明显提升;
  • 访问http://localhost:8080/user/username/test1,同理,第一次查询走数据库,后续走缓存。

3.2 @CacheEvict:删除缓存(核心注解)

作用:当数据发生修改(更新、删除)时,删除对应的缓存,避免缓存与数据库数据不一致(缓存脏数据)。

核心参数(常用):

  • value/cacheNames:缓存名称(必填),与@Cacheable的value一致;
  • key:要删除的缓存key(可选),与@Cacheable的key对应;
  • allEntries:是否删除该缓存名称下的所有缓存(可选,默认false);
  • beforeInvocation:是否在方法执行前删除缓存(可选,默认false,方法执行后删除)。
// 在UserController中新增更新、删除接口,添加@CacheEvict注解
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
/**
 * 示例3:更新用户信息(删除对应缓存,避免脏数据)
 * @CacheEvict:删除key为#user.id的缓存
 */
@CacheEvict(value = "user", key = "#user.id")
@PutMapping("/update")
public String updateUser(@RequestBody SysUser user) {
    boolean success = sysUserService.updateById(user);
    return success ? "用户更新成功,缓存已删除" : "用户更新失败";
}
/**
 * 示例4:删除用户(删除对应缓存)
 */
@CacheEvict(value = "user", key = "#userId")
@DeleteMapping("/{userId}")
public String deleteUser(@PathVariable Long userId) {
    boolean success = sysUserService.removeById(userId);
    return success ? "用户删除成功,缓存已删除" : "用户删除失败";
}
/**
 * 示例5:批量删除用户(删除user缓存下的所有缓存)
 * allEntries = true:删除value="user"下的所有缓存
 */
@CacheEvict(value = "user", allEntries = true)
@DeleteMapping("/batchDelete")
public String batchDeleteUser(@RequestBody List<Long> userIds) {
    boolean success = sysUserService.removeByIds(userIds);
    return success ? "批量删除成功,用户缓存全部清空" : "批量删除失败";
}

测试效果:

  • 先访问/user/1,缓存成功存入Redis;
  • 访问/update接口,更新ID为1的用户信息,执行完成后,Redis中key为springboot:cache:user::1的缓存被删除;
  • 再次访问/user/1,控制台打印SQL,重新查询数据库并缓存,确保缓存与数据库数据一致。

四、核心实战三:热点数据缓存案例(落地项目)

项目中最适合用缓存的就是「热点数据」——频繁查询、不常变化的数据,如用户信息、商品信息、字典数据等。本次以「商品列表+商品详情」为案例,落地热点数据缓存,模拟真实项目场景,让缓存优化真正发挥作用。

4.1 案例准备:商品实体与Service层

// 1. 商品实体类(Product)
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
@TableName("product")
public class Product {
    @TableId(type = IdType.AUTO)
    private Long id;
    private String productName; // 商品名称
    private BigDecimal price; // 商品价格
    private String description; // 商品描述
    private Integer stock; // 库存
    private LocalDateTime createTime; // 创建时间
}
// 2. 商品Mapper接口
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.Product;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ProductMapper extends BaseMapper<Product> {
}
// 3. 商品Service层
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.Product;
import com.example.demo.mapper.ProductMapper;
import org.springframework.stereotype.Service;
@Service
public class ProductService extends ServiceImpl<ProductMapper, Product> {
}

4.2 热点数据缓存实现(Controller)

商品列表(分页)和商品详情是典型的热点数据,频繁被用户访问,且商品信息不会频繁修改,适合缓存。结合@Cacheable、@CacheEvict实现缓存优化:

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.entity.Product;
import com.example.demo.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * 商品缓存案例控制器(热点数据缓存)
 */
@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private ProductService productService;
    /**
     * 热点数据1:商品详情(根据商品ID查询)
     * 缓存key:product:id:xxx,缓存过期时间30分钟(1800秒)
     * 说明:商品详情访问频繁,且修改频率低,适合长期缓存
     */
    @Cacheable(value = "product", key = "'id:'+#productId", expire = 1800)
    @GetMapping("/{productId}")
    public Product getProductById(@PathVariable Long productId) {
        System.out.println("执行数据库查询:查询商品详情,ID=" + productId);
        return productService.getById(productId);
    }
    /**
     * 热点数据2:商品列表(分页,无筛选条件)
     * 缓存key:product:list:pageNum:xxx:pageSize:xxx
     * 说明:首页商品列表访问量极高,缓存分页数据,减轻数据库压力
     */
    @Cacheable(value = "product", key = "'list:pageNum:'+#pageNum+':pageSize:'+#pageSize")
    @GetMapping("/list")
    public IPage<Product> getProductList(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        System.out.println("执行数据库查询:商品列表分页,页码=" + pageNum + ",每页条数=" + pageSize);
        Page<Product> page = new Page<>(pageNum, pageSize);
        QueryWrapper<Product> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("create_time"); // 按创建时间降序
        return productService.page(page, queryWrapper);
    }
    /**
     * 商品新增(无需缓存,新增后无查询缓存)
     */
    @PostMapping("/add")
    public String addProduct(@RequestBody Product product) {
        boolean success = productService.save(product);
        return success ? "商品新增成功" : "商品新增失败";
    }
    /**
     * 商品更新(删除对应商品详情缓存和列表缓存)
     * 说明:更新商品后,删除该商品的详情缓存和所有列表缓存,避免脏数据
     */
    @CacheEvict(value = "product", allEntries = true)
    @PutMapping("/update")
    public String updateProduct(@RequestBody Product product) {
        boolean success = productService.updateById(product);
        return success ? "商品更新成功,所有商品缓存已清空" : "商品更新失败";
    }
    /**
     * 商品删除(删除对应缓存)
     */
    @CacheEvict(value = "product", key = "'id:'+#productId")
    @DeleteMapping("/{productId}")
    public String deleteProduct(@PathVariable Long productId) {
        boolean success = productService.removeById(productId);
        return success ? "商品删除成功,对应缓存已删除" : "商品删除失败";
    }
}

4.3 案例测试与效果验证

  • 访问商品列表接口:http://localhost:8080/product/list?pageNum=1&pageSize=10,第一次执行数据库查询(打印SQL),Redis中存入缓存;第二次访问,直接返回缓存,响应速度提升50%以上;
  • 访问商品详情接口:http://localhost:8080/product/1,第一次查询走数据库,后续走缓存;
  • 执行商品更新接口,更新ID为1的商品信息,执行完成后,Redis中所有product缓存被清空;再次访问列表和详情接口,重新查询数据库并缓存;
  • 查看Redis客户端,可看到缓存的商品列表和详情数据(JSON格式),过期时间正常生效。

案例优化建议:1. 商品列表缓存可根据实际需求调整过期时间(如1小时),避免缓存数据过旧;2. 若商品列表有筛选条件(如按分类筛选),可在key中添加筛选参数(如key = “‘list:category:’+#categoryId+‘:pageNum:’+#pageNum”);3. 高并发场景下,可添加缓存预热(项目启动时提前加载热点数据到Redis)。

五、常见问题与解决方案(缓存落地避坑)

缓存注解不生效?
解决方案:① 检查启动类是否添加@EnableCaching注解;② 注解标注的方法必须是public方法,且不能是static、private方法;③ 注解标注的类必须添加@Component(或@Controller、@Service),交给Spring管理;④ 避免在同一个类中调用标注缓存注解的方法(Spring AOP代理机制限制)。

Redis缓存中文乱码、对象无法反序列化?

解决方案:配置自定义缓存序列化方式(如本文1.5节的配置),使用GenericJackson2JsonRedisSerializer将对象序列化为JSON格式,避免默认的二进制序列化。

缓存与数据库数据不一致(脏数据)?

解决方案:① 数据更新、删除时,必须使用@CacheEvict删除对应缓存;② 复杂场景(如多表关联更新),可使用@CacheEvict(allEntries = true)清空对应缓存;③ 避免缓存过期时间过长,合理设置过期时间。

缓存穿透(查询不存在的数据,频繁访问数据库)?

解决方案:① 配置cache-null-values: true,缓存null值(但需注意过期时间,避免缓存大量null值占用内存);② 在接口层添加参数校验,过滤无效参数;③ 使用布隆过滤器,提前拦截不存在的key。

Redis连接失败,项目启动报错?

解决方案:① 检查Redis服务是否正常启动;② 确认Redis连接配置(host、port、password)正确;③ 检查服务器防火墙是否开放Redis端口(6379);④ 若使用远程Redis,确认远程连接权限开启。

六、总结(缓存优化提升项目专业度)

本文承接项目数据量大后的性能优化需求,完整实战了Spring Boot集成Redis缓存的核心流程,从环境搭建、缓存注解使用,到热点数据缓存案例,帮你快速落地缓存优化,核心要点总结:

  • 集成Redis:引入核心依赖,配置Redis连接信息和序列化方式,开启缓存功能(@EnableCaching),确保Redis环境可用;
  • 核心注解:@Cacheable实现查询缓存,减少数据库查询;@CacheEvict实现缓存删除,避免脏数据,两个注解覆盖大多数缓存场景;
  • 热点缓存案例:以商品列表、商品详情为核心,落地真实项目场景,让缓存真正发挥性能优化作用,提升接口响应速度;
  • 避坑要点:解决缓存注解失效、中文乱码、数据不一致等常见问题,确保缓存功能稳定运行,适配生产环境。

掌握本文内容后,你可以轻松将Redis缓存集成到自己的项目中,解决数据量大带来的性能瓶颈,让接口响应速度翻倍,同时降低数据库压力——这不仅能提升项目的实用性和用户体验,更能让你的项目在同类产品中显得更专业、更具竞争力。后续可进一步扩展:缓存预热、缓存降级、分布式缓存一致性等高级功能,让缓存优化更完善。

到此这篇关于Spring Boot 缓存优化Redis 实战指南的文章就介绍到这了,更多相关Spring Boot 缓存优化内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • Java中自定义泛型方法及其应用示例代码

    Java中自定义泛型方法及其应用示例代码

    泛型方法是Java中一个强大的特性,它允许我们在方法级别使用类型参数,提高代码的复用性和类型安全性,通过本文,读者可以学习如何定义和使用泛型方法,并了解其在处理集合、比较对象、创建实例等任务中的应用,感兴趣的朋友一起看看吧
    2025-02-02
  • dubbo自定义异常的完整步骤与测试

    dubbo自定义异常的完整步骤与测试

    最近在项目上遇到一个有关dubbo的问题,想着给大家总结下,这篇文章主要给大家介绍了关于dubbo自定义异常的完整步骤与测试的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下
    2022-06-06
  • Java File类的简单使用教程(创建、删除、遍历与判断是否存在等)

    Java File类的简单使用教程(创建、删除、遍历与判断是否存在等)

    这篇文章主要给大家介绍了关于Java File类的简单使用(创建、删除、遍历与判断是否存在等)的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-12-12
  • Spring的异常重试框架Spring Retry简单配置操作

    Spring的异常重试框架Spring Retry简单配置操作

    这篇文章主要介绍了Spring的异常重试框架Spring Retry简单配置操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-09-09
  • Spring Security如何基于Authentication获取用户信息

    Spring Security如何基于Authentication获取用户信息

    这篇文章主要介绍了Spring Security如何基于Authentication获取用户信息,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-03-03
  • B/S与C/S架构的区别介绍

    B/S与C/S架构的区别介绍

    本文详细讲解了B/S与C/S架构的区别,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-12-12
  • Spring中实现定时调度的几种方法

    Spring中实现定时调度的几种方法

    本篇文章主要介绍了Spring中实现定时调度示例,可以在无人值守的时候系统可以在某一时刻执行某些特定的功能,有兴趣的可以了解一下。
    2017-02-02
  • SpringBoot实现过滤敏感词的示例代码

    SpringBoot实现过滤敏感词的示例代码

    这篇文章主要为大家详细介绍了如何利用SpringBoot实现过滤敏感词功能,文中的示例代码讲解详细,感兴趣的小伙伴可以动手尝试一下
    2022-08-08
  • PL/SQL实现JAVA中的split()方法的例子

    PL/SQL实现JAVA中的split()方法的例子

    这篇文章主要介绍了PL/SQL实现JAVA中的split()方法的例子的相关资料,非常不错,具有参考借鉴价值,需要的朋友可以参考下
    2016-07-07
  • SpringCloud+nacos部署在多ip环境下统一nacos服务注册ip(亲测有效)

    SpringCloud+nacos部署在多ip环境下统一nacos服务注册ip(亲测有效)

    在部署SpringCoud项目的时候分服务器部署注册同一个nacos服务,但是在服务器有多个ip存在的同时(内外网),就会出现注册服务ip不同的问题,导致一些接口无法连接访问,经过多次排查终于找到问题并找到解决方法,需要的朋友可以参考下
    2023-04-04

最新评论