簡體   English   中英

Spring Ehcache 配置:java.lang.IllegalStateException:錯誤

[英]Spring Ehcache configuration : java.lang.IllegalStateException: error

pom.xml

 <properties>
    <jdk.version>1.8</jdk.version>
    <spring.framework.version>5.1.6.RELEASE</spring.framework.version>
    <spring.security.version>3.2.9.RELEASE</spring.security.version>
    <spring.integration.version>5.1.4.RELEASE</spring.integration.version>
</properties>

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${spring.security.version}</version>
</dependency>

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>${spring.security.version}</version>
</dependency>

<dependency>
    <groupId>net.sf.ehcache</groupId>
    <artifactId>ehcache</artifactId>
    <version>2.10.6</version>
</dependency>

緩存文件

<cache name="myList" 
    overflowToDisk="false"  statistics="true"
    eternal="false"
    maxElementsInMemory="10000"
    timeToIdleSeconds="0"
    timeToLiveSeconds="300"
    memoryStoreEvictionPolicy="LFU" />

Java文件

     public class MyClass
  {
    
    public final Map<String, String> getDepartmentsList(String userid) {
        System.out.println("I am getting the dept");
        Map<String, String> deptMap = myService.getAuthorizedDept(userid);
        return deptMap;
    }
 }
 
@Service 
import org.springframework.cache.annotation.Cacheable;
public class Myservice
{
@Cacheable(value = "myList", keyGenerator = "cacheKeyGenerator" )
    public Map<String, String> getDepartmentsList(String userid){
    }
}

cache-service.xml cacheManager 配置。 我認為我的不正確,這就是我收到錯誤的原因。 我不確定出了什么問題。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cache="http://www.springframework.org/schema/cache"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/cache 
        http://www.springframework.org/schema/cache/spring-cache.xsd">
    <cache:annotation-driven />

    <bean id="cacheManager"
        class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
        <property name="shared" value="true" />
    </bean>

    <bean id="cacheKeyGenerator"
        class="test.util.StringArgumentCacheKeyGenerator" />
</beans>

錯誤堆棧:

Caused by: java.lang.IllegalStateException:Cannot convert value of type 'net.sf.ehcache.CacheManager' to required type 'org.springframework.cache.CacheManager' for property 'cacheManager':
no matching editors or conversion strategy found
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'org.springframework.cache.interceptor.CacheInterceptor#0':
 Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException:
 Failed to convert property value of type 'net.sf.ehcache.CacheManager' to required type 'org.springframework.cache.CacheManager' for property 'cacheManager';nested exception is java.lang.IllegalStateException: Cannot convert value of type 

以下 cache-service.xml 對我有用。

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
xmlns:cache="http://www.springframework.org/schema/cache" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/tx 
          http://www.springframework.org/schema/tx/spring-tx.xsd
          http://www.springframework.org/schema/mvc 
          http://www.springframework.org/schema/mvc/spring-mvc.xsd
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/cache
          http://www.springframework.org/schema/cache/spring-cache.xsd">

<cache:annotation-driven />

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
    <property name="cacheManager">
        <ref local="ehcache" />
    </property>
</bean>

<bean id="ehcache"
    class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
    p:configLocation="classpath:ehcache.xml" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM