2016-08-21 2 views
4

실패, 다음과 같은 오류가 발생합니다봄 - 데이터 - 레디 스는 1.7.2 주입 redisTemplate이

@Bean 
public RedisConnectionFactory jedisConnectionFactory() { 
    nodes = new ArrayList<String>(); 
    nodes.add("10.10.13.174:7001"); 
    nodes.add("10.10.13.174:7002"); 
    nodes.add("10.10.13.174:7003"); 
    RedisClusterConfiguration conf = new RedisClusterConfiguration(nodes); 
    conf.setMaxRedirects(1000); 
    JedisConnectionFactory factory = new JedisConnectionFactory(conf); 

    return factory; 
} 

@Bean 
RedisTemplate<Object, Object> redisTemplate() { 
    RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<Object, Object>(); 
    redisTemplate.setConnectionFactory(jedisConnectionFactory()); 
    return redisTemplate; 
} 

나의 봄 : 여기

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisTemplate' defined in com.worktime.configure.JpaConfigurationTest: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.springframework.core.serializer.support.DeserializingConverter.<init>(Ljava/lang/ClassLoader;)V 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305) 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) 
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834) 
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537) 
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:125) 
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) 
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:109) 
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:261) 
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98) 
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116) 
... 25 more 
Caused by: java.lang.NoSuchMethodError: org.springframework.core.serializer.support.DeserializingConverter.<init>(Ljava/lang/ClassLoader;)V 
at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.<init>(JdkSerializationRedisSerializer.java:53) 
at org.springframework.data.redis.core.RedisTemplate.afterPropertiesSet(RedisTemplate.java:117) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) 
... 40 more 

내 코드입니다 데이터 redis 버전은 1.7.2이고 redis 버전은 2.8.1입니다.

+1

. 스프링 데이터 Redis는 더 새로운 생성자를 사용합니다. [here] (http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/core/serializer/support/DeserializingConverter.html#DeserializingConverter-java .lang.ClassLoader-) – mp911de

+0

4.3.2로 변경되었습니다. 잘 작동합니다. 감사합니다.^_^ –

+0

@webdavid 위의 내용을 XML로 구성하는 방법은? 설명과 동일한 문제가 있습니다. 스프링 데이터 Redis 사용 1.7.2.RELEASE 및 Spring 4.3.2. RedisCacheManager를 동일한 버전으로 구성하는 방법은 무엇입니까? – nijogeorgep

답변

1

스프링 데이터 Redis 1.7.2.RELEASE와 함께 사용하려면 다음 구성을 사용하십시오. 분사 문제가 발생하지 않습니다.

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

    <!-- Redis Connection Factory --> 
    <beans:bean id="jedisConnectionFactory" 
     class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" 
     p:host-name="${redis.host-name}" p:port="${redis.port}" p:use-pool="true" /> 

    <!-- Redis Template Definition --> 
    <beans:bean id="redisTemplate" 
     class="org.springframework.data.redis.core.RedisTemplate" 
     p:connection-factory-ref="jedisConnectionFactory" p:keySerializer-ref="stringRedisSerializer" 
     p:hashKeySerializer-ref="stringRedisSerializer" /> 

    <beans:bean id="stringRedisSerializer" 
     class="org.springframework.data.redis.serializer.StringRedisSerializer" /> 

    <!-- declare Redis Cache Manager --> 
    <beans:bean id='redisCacheManager' 
     class='org.springframework.data.redis.cache.RedisCacheManager' 
     c:redis-operations-ref='redisTemplate'> 
    </beans:bean> 
+0

니스. 감사합니다. 하지만 스프링 버전을 변경해야했습니다. – cdesmetz

1

bean 정의를 변경하지 않고 Spring 버전을 프로젝트 pom으로 변경하기 만하면됩니다.

<bean id="jedisConnectionFactoryStatic"  class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> 
    <property name="hostName" value="#{confMasterRedisStatic.host}" /> 
    <property name="port"  value="#{confMasterRedisStatic.port}" /> 
    <property name="usePool" value="true" /> 
</bean> 

<bean id="redisTemplateStatic" class="org.springframework.data.redis.core.StringRedisTemplate" 
     p:connection-factory-ref="jedisConnectionFactoryStatic" /> 

의 pom.xml

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <!-- <spring.version>3.0.7.RELEASE</spring.version> --> 
    <spring.version>4.3.3.RELEASE</spring.version> 
</properties> 

<dependency> 
    <groupId>org.springframework.data</groupId> 
    <artifactId>spring-data-redis</artifactId> 
    <version>1.7.4.RELEASE</version> 
    <!-- <version>1.5.2.RELEASE</version> --> 
</dependency> 
은 스프링 코어 프레임 워크 적어도 4.2.1 업그레이드
관련 문제