首页 > 解决方案 > mybatis mapper注解中无法创建hazelcast缓存

问题描述

我设计了数据访问对象 mybatis 映射器来从 Mysql 数据库中读取只读数据。

 @Mapper
    public interface XYZMapper {
    
        @Select("SELECT TYPES FROM abc  WHERE STORE_ID = #{storeId}  and CUSTOMER_ID = #{customerId}")
        public String getDisabledSubscriptions(@Param("storeId") int storeId, @Param("customerId") int customerId);
    
        @Select("SELECT TYPES as messageTypes, NAME as eventName FROM abc  WHERE STORE_ID = #{storeId}")
        public EventSubscription getEventAllSubscriptions(@Param("storeId") int storeId);

http://mybatis.org/hazelcast-cache/

上面的链接给出了使用 hazelcast 进行缓存的解决方案。这在我们将映射器配置为 xml 文件时使用。我们如何使用注释映射器将上述每个查询缓存为 L2 缓存

标签: mybatishazelcastspring-cachespring-mybatismybatis-mapper

解决方案


通过以下步骤解决了问题

a) @EnableCaching 与 SpringBootApplication 类

b)在映射器中定义的每个数据库方法中添加@Cacheable(“abc”)(您想要缓存)

c) 在资源文件夹中定义 hazelcast.yml

hazelcast:网络:加入:多播:启用:真


推荐阅读