org.springframework.beans.factory.BeanNotOfRequiredTypeException в хранилище - PullRequest
0 голосов
/ 27 сентября 2018

Я хочу сделать метод репозитория кэшируемым, используя аннотацию @Cacheable.

Здесь мой класс (добавлены только необходимые материалы):

@Repository
public class FclmConfigurationRepository  {

@Cacheable(value="fclmConfiguration", key="#key")
public List<FclmConfiguration> findFclmConfiguration(String key) {
    return something;
}

Но когда я пытаюсь использоватьэтот репозиторий в реализации сервиса (добавлены только необходимые материалы)

@Autowired
private FclmConfigurationRepository repository;

public List<FclmConfiguration> getFclmConfiguration(FclmConfiguration configuration) {
    return repository.findFclmConfiguration(configuration);
}

Я получаю следующую ошибку: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'XXX' is expected to be of type 'XXX' but was actually of type 'com.sun.proxy.$Proxy79'

Я действительно знаю, почему это происходит, но я не знаю, какЧтобы решить эту проблему - любой совет?

Вот мои другие конфигурации:

cache.xml:

<?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-4.3.xsd
    http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
    ">

<cache:annotation-driven cache-manager="cacheManager" />

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

<!-- Ehcache library setup -->
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="configLocation" value="/WEB-INF/ehcache.xml" />
    <property name="shared" value="true" />
</bean>

ehcache.xml:

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="ehcache.xsd"
     updateCheck="true" 
     monitoring="autodetect"
     dynamicConfig="true">

<defaultCache
        eternal="false"
        timeToIdleSeconds="900"
        timeToLiveSeconds="900"
        diskSpoolBufferSizeMB="30"
        diskExpiryThreadIntervalSeconds="120"
        memoryStoreEvictionPolicy="LRU">
</defaultCache>

<cache name="fclmConfiguration"
    eternal="false"
    maxElementsInMemory="10000"
    overflowToDisk="false"
    diskPersistent="false"
    timeToIdleSeconds="0"
    timeToLiveSeconds="900"
    memoryStoreEvictionPolicy="LRU"
/>

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...