Mybatis + Shiro 使用ehcache做二级缓存 曾经终败给现在 2022-05-25 13:09 175阅读 0赞 ## 1、mybatis的ehcache依赖: ## <!-- mybatis + ehcache start--> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-ehcache</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>org.ehcache</groupId> <artifactId>ehcache</artifactId> <version>3.0.1</version> </dependency> <!-- mybatis + ehcache end--> ## 2、shiro的ehcache依赖: ## <!-- shiro start--> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-spring</artifactId> <version>1.2.3</version> </dependency> <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache-core</artifactId> <version>2.6.9</version> </dependency> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-ehcache</artifactId> <version>1.2.3</version> </dependency> <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache-web</artifactId> <version>2.0.4</version> </dependency> <!-- shiro end --> ## 3、因为两者都有ehcache,所以需要共享ehcache,mybatis配置文件中,加入: ## <!-- MyBatis使用ehcache缓存 start --> <bean id="ehCacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> <property name="configLocation" value="classpath:ehcache.xml"/> <!-- 和shiro分享缓存 --> <property name="shared" value="true"></property> </bean> <!-- end MyBatis使用ehcache缓存 --> <!-- shiro缓存管理器 使用Ehcache实现 --> <bean id="shiroCacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager"> <property name="cacheManager" ref="ehCacheManager" /> </bean> ## 4、作用 ## 1、使mybatis和shiro共享ehcache 2、使同一个查询,只查询一次,第一次查询后,放到ehcache里面,后面直接从缓存取
还没有评论,来说两句吧...