EhCache
を使用して私のプロジェクトでキャッシュを実装しています。私は私のpom.xmlに以下の依存関係を追加したはnet.sf.ehcache.CacheManagerにアクセスできません.net.sf.ehcache.CacheManagerのクラスファイルは見つかりません
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.ehcache/ehcache -->
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>3.3.1</version>
</dependency>
はEhCache
ためである第三の依存関係に注意してください。私がオンラインで見つけたすべてのチュートリアルでは、グループIDが異なります。私がグループIDを変更する理由は、org.ehcache
に移動されたためです。
クラスパスに次のehcache.xmlファイルがあります。
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="true"
monitoring="autodetect"
dynamicConfig="true">
<diskStore path="java.io.tmpdir"/>
<cache name="cardTypes"
maxEntriesLocalHeap="100"
maxEntriesLocalDisk="1000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LFU"
transactionalMode="off">
<persistence strategy="localTempSwap"/>
</cache>
</ehcache>
以下は私の設定ファイルです。
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.cache.CacheManager;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.core.io.ClassPathResource;
@EnableCaching
@Configuration
public class CacheConfig {
@Bean
public CacheManager cacheManager() {
return new EhCacheCacheManager(ehCacheCacheManager().getObject());
}
@Bean
public EhCacheManagerFactoryBean ehCacheCacheManager() {
EhCacheManagerFactoryBean factory = new EhCacheManagerFactoryBean();
factory.setConfigLocation(new ClassPathResource("ehcache.xml"));
factory.setShared(true);
return factory;
}
}
ここでは、次の行に誤りがあります。 Eclipseで
:ある
return new EhCacheCacheManager(ehCacheCacheManager().getObject());
-
net.sf.ehcache.CacheManagerを解決できないタイプ。それはJIdeaに必要な.classファイルから間接的に参照
です:
Error:(21, 71) java: cannot access net.sf.ehcache.CacheManager class file for net.sf.ehcache.CacheManager not found
私は私のプロジェクトに任意のnet.sf.ehcacheものを追加していません。前述のとおり、ehcache
はorg.ehcache
に移動されました。
なぜこのエラーが発生しますか?これは私が追加した依存関係の一部ではないnet.sf.ehcache
に関連しています。
アーティファクトが移動されたため、別の方法で2番目のBeanをコーディングする必要がありますか?どうすれば解決できますか?
ありがとうございます。いくつかのことを試した後、私が思いついた解決策は古いEhcache 2を使用することでした。それが問題を解決しました。しかし、これも解決策です。私はこれを受け入れています。 :) – vigamage
ありがとう;-)私が言ったように、依存関係をehcache 2に移すことは、もちろん動作します:-) – Henri