将ehcache 3与Spring注释一起使用(不使用Spring Boot) [英] Using ehcache 3 with Spring Annotations (not using Spring Boot)

查看:359
本文介绍了将ehcache 3与Spring注释一起使用(不使用Spring Boot)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让Ehcache 3在不使用Spring引导的情况下与Spring 4一起使用.

I'm trying to get Ehcache 3 working with Spring 4 without using Spring boot.

此处是一个使用Spring Boot的有效示例,但是我正在开发一个不使用Spring Boot的现有应用程序.

Here is a working example out there which uses Spring Boot, but I'm working on an existing application which is not using Spring Boot.

问题在于spring-context-support(添加了Spring的缓存注释)希望Ehcache的CacheManager处于以下类路径中:net.sf.ehcache.CacheManager

The problem is that spring-context-support (which adds Spring's cache annotations) expects the Ehcache's CacheManager to be on this classpath: net.sf.ehcache.CacheManager

但是,在Ehcache 3中,CacheManager类位于另一个类路径:org.ehcache.CacheManager.

However, in Ehcache 3, the CacheManager class resides on another classpath: org.ehcache.CacheManager.

因此,基本上,spring-context-support不支持Ehcache3.您将必须直接使用JSR-107批注,而不是Spring提供的批注.

So, basically spring-context-support does not support Ehcache 3. And you would have to use the JSR-107 annotations directly, not the annotations provided by Spring.

但是显然,它可以与Spring Boot一起使用.也许还有一种方法可以使其与标准Spring Application一起使用.那就是我所希望的.我真的很想使用Spring自己的注释,而不是JSR-107注释.

But apparently it works with Spring Boot. Perhaps there is a way to make it work with a standard Spring Application as well. That's what I'm hoping. I really want to be using Spring's own annotations instead of the JSR-107 annotations.

推荐答案

实际上,Spring Caching中没有对Ehcache 3的原生支持.

Indeed there is no native support of Ehcache 3 in Spring Caching.

好消息是,您可以通过. rel ="noreferrer">兼容的JCache实现. 一旦在应用程序上下文中有一个JCache CacheManager可用,任何强制您使用JCache批注的内容.您可以毫无问题地继续使用Spring Caching.

The good news is that you achieve what you want with the JCache support that Spring Caching has since Ehcache 3 is a compliant JCache implementation. And once you have a JCache CacheManager available in your application context, nothing forces you to use the JCache annotations. You can keep using the Spring Caching ones without any problem.

您可以在此处找到演示.

注意:我正在使用Ehcache

Note: I am working on Ehcache

这篇关于将ehcache 3与Spring注释一起使用(不使用Spring Boot)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆