spring整合redis问题

报错No qualifying bean of type [org.springframework.data.redis.core.RedisTemplate]
可能原因:spring版本问题,我将spring版本调到4.0.6的话报的这个错误,调回3.2.3没有问题,主要是下面几个spring插件的版本问题造成的。

<dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-context</artifactId>  
            <version>3.2.3.RELEASE</version>  
        </dependency>  

        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-context-support</artifactId>  
            <version>3.2.3.RELEASE</version>  
        </dependency>  

        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-beans</artifactId>  
            <version>3.2.3.RELEASE</version>  
        </dependency> 

我的application-config.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:p="http://www.springframework.org/schema/p"  
    xmlns:context="http://www.springframework.org/schema/context"  
    xmlns:jee="http://www.springframework.org/schema/jee" 
    xmlns:tx="http://www.springframework.org/schema/tx"  
    xmlns:aop="http://www.springframework.org/schema/aop"  
    xsi:schemaLocation="  
            http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans.xsd  
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context.xsd">  

         <context:component-scan
            base-package="com.hainan.cs"/>  
<context:property-placeholder location="classpath:redis.properties" />  
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">  
        <property name="maxIdle" value="${redis.maxIdle}" />  
        <property name="testOnBorrow" value="${redis.testOnBorrow}" />  
    </bean>  

    <bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"  
        p:host-name="${redis.host}" p:port="${redis.port}"   p:pool-config-ref="poolConfig" p:password="${redis.pass}"/>  

    <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">  
        <property name="connectionFactory"   ref="connectionFactory" />  
    </bean>     
    <bean id="userDao" class="com.hainan.cs.dao.UserDaoImp"></bean>  
</beans>

猜你喜欢

转载自blog.csdn.net/khuangliang/article/details/53673951