存储库中的org.springframework.beans.factory.BeanNotOfRequiredTypeException

时间:2018-09-27 08:49:14

标签: java caching repository ehcache

我想通过使用@Autowire批注来使存储库方法可行。

这是我的课(仅添加了必要的内容):

@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); }

我实际上知道为什么会这样,但是我不知道如何解决-有任何建议吗?

这是我的其他配置:

cache.xml:

org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'XXX' is expected to be of type 'XXX' but was actually of type 'com.sun.proxy.$Proxy79'

ehcache.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>

0 个答案:

没有答案