hibernate redis 二级缓存使用 spring boot redis 配置

Overview

hibernate-redisson-spring-boot-starter

介绍

使用 Redisson 作为 hibernate redis 二级缓存提供器,redisson-hibernate-53(hibernate-version) 无法使用 spring boot 配置文件创建的 org.redisson.api.RedissonClient bean, 而redisson-spring-boot-starter 为 spring boot redis 自动配置的一个实现,且会创建 org.redisson.api.RedissonClient bean,hibernate-redisson-spring-boot-starter 的作用就是结合这两个库 的功能从而实现 hibernate redis 二级缓存提供器的 redis client 配置可以使用 spring boot redis 配置,更加的灵活且不需要单独为 hibernate 二级缓存再提供一份 redis 配置。

原理

org.springframework.beans.factory.config.BeanFactoryPostProcessor调用后才会去创建 bean, 创建 entityManagerFactory 这个 bean 的时候会创建二级缓存需要的缓存提供器, 这时候通过 beanFactory 去取 org.redisson.api.RedissonClient bean,这个时候 org.redisson.api.RedissonClient bean 还没创建,这个时候就会创建这个 bean,创建完后返回。

使用

  • 引入依赖即可

    <dependency>
        <groupId>cn.inusha</groupId>
        <artifactId>hibernate-redisson-spring-boot-starter</artifactId>
        <version>1.0.1</version>
    </dependency>

针对不同 spring boot 版本、hibernate 版本

  • 根据下面的依赖关系排除掉不合适的依赖并引入合适的依赖,比如

    <dependencies>
        <dependency>
            <groupId>cn.inusha</groupId>
            <artifactId>hibernate-redisson-spring-boot-starter</artifactId>
            <version>1.0.1</version>
            <exclusions>
                <exclusion>
                    <artifactId>redisson-spring-data-24</artifactId>
                    <groupId>org.redisson</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <artifactId>redisson-spring-data-22</artifactId>
            <groupId>org.redisson</groupId>
            <version>${redisson.version}</version>
        </dependency>
    </dependencies>
  • redisson-hibernate 依赖关系

    <dependency>
        <groupId>org.redisson</groupId>
        <!-- for Hibernate v4.x -->
        <artifactId>redisson-hibernate-4</artifactId>
        <!-- for Hibernate v5.0.x - v5.1.x -->
        <artifactId>redisson-hibernate-5</artifactId>
        <!-- for Hibernate v5.2.x -->
        <artifactId>redisson-hibernate-52</artifactId>
        <!-- for Hibernate v5.3.3+ - v5.4.x -->
        <artifactId>redisson-hibernate-53</artifactId>
        <version>3.15.5</version>
    </dependency>
  • redisson-spring-boot-starter 依赖需要的 redisson-spring-data-xx 和 spring 关系

    redisson-spring-data
    module name
    Spring Boot
    version
    redisson-spring-data-16 1.3.x
    redisson-spring-data-17 1.4.x
    redisson-spring-data-18 1.5.x
    redisson-spring-data-20 2.0.x
    redisson-spring-data-21 2.1.x
    redisson-spring-data-22 2.2.x
    redisson-spring-data-23 2.3.x
    redisson-spring-data-24 2.4.x
You might also like...

Spring-boot application using redis as a caching database

Java Spring-boot application using Redis as a caching database Running Application Entities involved Two main entities are involved MasterHouse (maste

Aug 9, 2022

about learning Spring Boot via examples. Spring Boot 教程、技术栈示例代码,快速简单上手教程。

about learning Spring Boot via examples. Spring Boot 教程、技术栈示例代码,快速简单上手教程。

Spring Boot 学习示例 Spring Boot 使用的各种示例,以最简单、最实用为标准,此开源项目中的每个示例都以最小依赖,最简单为标准,帮助初学者快速掌握 Spring Boot 各组件的使用。 Spring Boot 中文索引 | Spring Cloud学习示例代码 | Spring

Jan 1, 2023

spring boot 实践学习案例,是 spring boot 初学者及核心技术巩固的最佳实践。另外写博客,用 OpenWrite。

spring boot 实践学习案例,是 spring boot 初学者及核心技术巩固的最佳实践。另外写博客,用 OpenWrite。

推荐工具: 微信公众号 Markdown 编辑器 - OpenWrite:Markdown 微信编辑器是一款专业强大的微信公众平台在线编辑排版工具,提供手机预览功能,让用户在微信图文 、文章、内容排版、文本编辑、素材编辑上更加方便。 - 更多介绍 博客群发平台 一、支持泥瓦匠 Spring Boot

Jan 5, 2023

Spring-Boot-Plus is a easy-to-use, high-speed, high-efficient,feature-rich, open source spring boot scaffolding

Spring-Boot-Plus is a easy-to-use, high-speed, high-efficient,feature-rich, open source spring boot scaffolding

Everyone can develop projects independently, quickly and efficiently! What is spring-boot-plus? A easy-to-use, high-speed, high-efficient, feature-ric

Dec 31, 2022

Two Spring-boot applications registering themselves to an spring-boot-admin-server application as separate clients for the purpose of monitoring and managing the clients

Two Spring-boot applications registering themselves to an spring-boot-admin-server application as separate clients for the purpose of monitoring and managing the clients

Spring-boot-admin implementation with 1 Server and 2 clients Creating a Server application to monitor and manage Spring boot applications (clients) un

Dec 6, 2022

The Spring Boot Sample App on K8S has been implemented using GKE K8S Cluster, Spring Boot, Maven, and Docker.

gke-springboot-sampleapp 👋 The Spring Boot Sample App on K8S has been implemented using GKE K8S Cluster, Spring Boot, Maven, and Docker. Usage To be

Feb 1, 2022

Spring Boot Migrator (SBM) - a tool for automated code migrations to upgrade or migrate to Spring Boot

Spring Boot Migrator (SBM) - a tool for automated code migrations to upgrade or migrate to Spring Boot

Spring Boot Migrator uses and is compatible to OpenRewrite, a powerful mass refactoring ecosystem for Java and other source code.

Jan 2, 2023

Dynamically filters JPA entities with a simple query syntax. Provides JPA/Hibernate predicates and Spring Data specifications.

Spring Filter You need a way to dynamically filter entities without any effort? Just add me to your pom.xml. Your API will gain a full featured search

Dec 13, 2022

This repository contains source code examples to support my course Spring Data JPA and Hibernate Beginner to Guru

Spring Data JPA - Spring Data JPA This repository contains source code examples to support my course Spring Data JPA and Hibernate Beginner to Guru Co

Aug 24, 2022
Owner
null
循序渐进,学习Spring Boot、Spring Boot & Shiro、Spring Batch、Spring Cloud、Spring Cloud Alibaba、Spring Security & Spring Security OAuth2,博客Spring系列源码:https://mrbird.cc

Spring 系列教程 该仓库为个人博客https://mrbird.cc中Spring系列源码,包含Spring Boot、Spring Boot & Shiro、Spring Cloud,Spring Boot & Spring Security & Spring Security OAuth2

mrbird 24.8k Jan 6, 2023
Spring Kurulumundan Başlayarak, Spring IOC ve Dependency Injection, Hibernate, Maven ve Spring Boot Konularına Giriş Yapıyoruz.

Spring Tutorial for Beginners File Directory Apache Tomcat Apache Tomcat - Eclipse Bağlantısı Spring Paketlerinin İndirilmesi ve Projeye Entegrasyonu

İbrahim Can Erdoğan 11 Apr 11, 2022
A simple quarkus app with hibernate as ORM, used to show the features of Hibernate Search

beer-manager-hibernate-search Project This project uses Quarkus, the Supersonic Subatomic Java Framework. If you want to learn more about Quarkus, ple

Sedona Solutions 3 Jan 6, 2022
Spring JPA Many To Many example with Hibernate and Spring Boot CRUD Rest API - ManyToMany annotation

Spring JPA Many To Many example with Hibernate and Spring Boot CRUD Rest API - ManyToMany annotation

null 17 Dec 28, 2022
Spring Boot, Hibernate, JpaRepository, RESTful services & PostgreSQL.

HRMS-Project Human Resources Management System Back End application with Java, Spring Boot, Hibernate, JpaRepository, RESTful services & PostgreSQL. S

Hikmet Tutuncu 9 Aug 23, 2022
Multi-Tenant Spring Boot Application with separate databases using Hibernate and H2.

Multi-Tenant Spring Boot Application A Spring Boot application that utilises a multi-tenancy architecture by providing multiple databases, one for eac

Alex Gschnitzer 15 May 9, 2022
The goal of the project is to create a web application using Java EE and database (PostgreSQL) without connecting a modern technology stack like spring boot and hibernate

About The Project SignIn page SignUp page Profile page The goal of the project is to create a web application using Java EE and database (PostgreSQL)

Islam Khabibullin 2 Mar 23, 2022
A code sharing platform built using spring boot, hibernate and JPA as ORM with PostgreSQL which also follows a RESTful architecture.

Snap-Snippet A code sharing platform built using spring boot, hibernate and JPA as ORM with PostgreSQL which also follows a RESTful architecture. Tech

Adnan Hossain 7 Nov 29, 2022
Um sistema de hospital feito em Spring Boot, contendo alguns CRUD's, e utilizando algumas famosas dependências, como o Hibernate. Vale destacar a interface inspirada no jogo Minecraft.

Introdução ✏ Esse projeto é uma atividade da disciplina de Design, Arquitetura e Construção de Software [DACS]. O objetivo do projeto é simular um sis

Ramon Victor Cardoso 12 Nov 6, 2022
Spring Boot Login and Registration example with MySQL, JWT, Rest Api - Spring Boot Spring Security Login example

Spring Boot Login example with Spring Security, MySQL and JWT Appropriate Flow for User Login and Registration with JWT Spring Boot Rest Api Architect

null 58 Jan 5, 2023