mybatis - 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 缓存
解决方案
通过以下步骤解决了问题
a) @EnableCaching 与 SpringBootApplication 类
b)在映射器中定义的每个数据库方法中添加@Cacheable(“abc”)(您想要缓存)
c) 在资源文件夹中定义 hazelcast.yml
hazelcast:网络:加入:多播:启用:真
推荐阅读
- spring-boot - Spring Boot 从 application.properties 中外部化属性
- java - 在字符串比较期间忽略无效字符
- visual-studio-code - 如何在 VS Code 中为 JS 文件禁用 dot emmet intellisense
- javascript - 将 React.js 和 Node.js 文件推送到 GitHub
- c# - 我应该将实体框架的 SaveChanges() 方法放在单独的方法中还是与其他方法一起使用?
- javascript - 如何从 html 内容中删除所有链接
- javascript - 如何防止基于日期比较的表单提交
- ios - SwiftUI ScrollView 和 OnLongPressGesture
- python - 你可以让程序在python中创建变量吗?
- javascript - 本文档需要 Angular 11 中的“TrustedScriptURL”分配