我尝试使用`Spring-data-redis
时发生错误 java.lang.VerifyError: (class: org/springframework/data/redis/connection/jedis/JedisConnectionFactory, method: afterPropertiesSet signature: ()V) Incompatible argument to function
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at de.hybris.platform.spring.LazyInitOverrideBeanFactoryPostProcessor.forName(LazyInitOverrideBeanFactoryPostProcessor.java:90)
at java.util.Optional.map(Optional.java:215)
我的pom.xml
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.8.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.2</version>
</dependency>
<!-- REDIS Drivers -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
<optional>true</optional>
</dependency>
xml文件中的Spring声明。到目前为止,我还没有从任何代码中自动布线它们。有了这个弹簧定义上下文初始化失败。我的类路径中首先存在maven依赖项
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal"
value="10" />
<property name="maxIdle"
value="10" />
<property name="minIdle"
value="0" />
</bean>
<alias name="jedisConnectionFactory" alias="jedisConnectionFactory" />
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="port" value="6379" />
<property name="timeout" value="600" />
<property name="hostName" value="127.0.0.1" />
<property name="password" value="" />
<property name="usePool" value="true" />
<property name="database" value="0" />
<property name="convertPipelineAndTxResults" value="true" />
<property name="poolConfig" ref="jedisPoolConfig" />
</bean>
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory" />
</bean>
我还尝试使用@Bean声明,这在许多其他地方建议使用。但这也给了同样的例外。
import org.apache.xpath.operations.String;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import redis.clients.jedis.JedisPoolConfig;
@Component
public class RedisConfig
{
@Bean
JedisPoolConfig jedisPoolConfig()
{
final JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
jedisPoolConfig.setMaxTotal(10);
jedisPoolConfig.setMaxIdle(10);
jedisPoolConfig.setMaxWaitMillis(6000);
return jedisPoolConfig;
}
@Bean
JedisConnectionFactory jedisConnectionFactory(final JedisPoolConfig jedisPoolConfig)
{
final JedisConnectionFactory factory = new JedisConnectionFactory();
factory.setPoolConfig(jedisPoolConfig);
factory.setHostName("127.0.0.1");
factory.setPort(6379);
factory.afterPropertiesSet();
return factory;
}
@Bean
public RedisTemplate<String, Object> redisTemplate(final JedisConnectionFactory jedisConnectionFactory)
{
final RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
template.setConnectionFactory(jedisConnectionFactory);
template.afterPropertiesSet();
return template;
}
}