请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

老师我配置Redis的时候报这个错:

 Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'areaServiceImpl': Unsatisfied dependency expressed through field 'jedisKeys'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jedisKey' defined in class path resource [spring/spring-redis.xml]: Cannot resolve reference to bean 'jedisUtil' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jedisUtil' defined in class path resource [spring/spring-redis.xml]: Cannot resolve reference to bean 'jedisWritePool' while setting bean property 'jedisPool'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jedisWritePool' defined in class path resource [spring/spring-redis.xml]: Cannot resolve reference to bean '127.0.0.1' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named '127.0.0.1' available

正在回答

1回答

同学好,应该是你的redis配置配错了 错误是 No bean named '127.0.0.1' available 没有127.0.0.1这个bean,请仔细与视频比对,以下是我的配置

spring-redis.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:context="http://www.springframework.org/schema/context"
	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">
	<!-- Redis连接池的设置 -->
	<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
		<!-- 控制一个pool可分配多少个jedis实例 -->
		<property name="maxTotal" value="${redis.pool.maxActive}" />
		<!-- 连接池中最多可空闲maxIdle个连接 ,这里取值为20,表示即使没有数据库连接时依然可以保持20空闲的连接,而不被清除,随时处于待命状态。 -->
		<property name="maxIdle" value="${redis.pool.maxIdle}" />
		<!-- 最大等待时间:当没有可用连接时,连接池等待连接被归还的最大时间(以毫秒计数),超过时间则抛出异常 -->
		<property name="maxWaitMillis" value="${redis.pool.maxWait}" />
		<!-- 在获取连接的时候检查有效性 -->
		<property name="testOnBorrow" value="${redis.pool.testOnBorrow}" />
	</bean>

	<!-- 创建Redis连接池,并做相关配置 -->
	<bean id="jedisWritePool" class="com.imooc.o2o.cache.JedisPoolWriper"
		depends-on="jedisPoolConfig">
		<constructor-arg index="0" ref="jedisPoolConfig" />
		<constructor-arg index="1" value="${redis.hostname}" />
		<constructor-arg index="2" value="${redis.port}" type="int" />
	</bean>

	<!-- 创建Redis工具类,封装好Redis的连接以进行相关的操作 -->
	<bean id="jedisUtil" class="com.imooc.o2o.cache.JedisUtil" scope="singleton">
		<property name="jedisPool">
			<ref bean="jedisWritePool" />
		</property>
	</bean>
	<!-- Redis的key操作 -->
	<bean id="jedisKeys" class="com.imooc.o2o.cache.JedisUtil$Keys"
		scope="singleton">
		<constructor-arg ref="jedisUtil"></constructor-arg>
	</bean>
	<!-- Redis的Strings操作 -->
	<bean id="jedisStrings" class="com.imooc.o2o.cache.JedisUtil$Strings"
		scope="singleton">
		<constructor-arg ref="jedisUtil"></constructor-arg>
	</bean>
	<!-- Redis的Lists操作 -->
	<bean id="jedisLists" class="com.imooc.o2o.cache.JedisUtil$Lists"
		scope="singleton">
		<constructor-arg ref="jedisUtil"></constructor-arg>
	</bean>
	<!-- Redis的Sets操作 -->
	<bean id="jedisSets" class="com.imooc.o2o.cache.JedisUtil$Sets"
		scope="singleton">
		<constructor-arg ref="jedisUtil"></constructor-arg>
	</bean>
	<!-- Redis的HashMap操作 -->
	<bean id="jedisHash" class="com.imooc.o2o.cache.JedisUtil$Hash"
		scope="singleton">
		<constructor-arg ref="jedisUtil"></constructor-arg>
	</bean>
</beans>


1 回复 有任何疑惑可以回复我~
  • 提问者 慕仙0279751 #1
    非常感谢翔哥!
    回复 有任何疑惑可以回复我~ 2018-07-11 10:04:43
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信