jedis单例访问redis报错:NOAUTH Authentication required.

ITnoLove 2017-05-26 10:44:38
感觉很揪心=.=需要用到一个redis,这个redis是设置访问密码的,即requirepass,但是我怎么配置才能设置访问密码呢?

	
<!-- 单机 -->
<bean id="jedisPool" class="redis.clients.jedis.JedisPool">
<constructor-arg name="host" value="127.0.0.1"></constructor-arg>
<constructor-arg name="port" value="6379"></constructor-arg>
</bean>
<bean id="jedisClientPool" class="jedis.JedisClientPool"></bean>


上面是简单的链接地址配置,
...全文
808 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ITnoLove 2017-05-26
  • 打赏
  • 举报
回复
引用 6 楼 qq_34580386 的回复:
我是这样配的,你看看有没有帮助。 <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"> <property name="maxIdle" value="${redis.maxIdle}" /> <property name="maxWaitMillis" value="1000" /> <property name="maxTotal" value="${redis.maxTotal}" /> </bean> <bean id="jedisPool" class="redis.clients.jedis.JedisPool"> <constructor-arg index="0" ref="jedisPoolConfig" /> <constructor-arg index="1" value="${redis.host}" /> <constructor-arg index="2" value="${redis.port}" /> <constructor-arg index="3" value="${redis.timeout}" /> <constructor-arg index="4" value="${redis.password}" /> </bean>
嗯嗯,我改成这样的就好了,谢谢你了啊哈
ITnoLove 2017-05-26
  • 打赏
  • 举报
回复
	<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
		<property name="maxIdle" value="300" />
		<property name="maxTotal" value="60000" />
		<property name="testOnBorrow" value="true" />
	</bean>

	<bean id="jedisPool" class="redis.clients.jedis.JedisPool">
		<constructor-arg index="0" ref="jedisPoolConfig" />
		<constructor-arg index="1" value="127.0.0.1" />
		<constructor-arg index="2" value="6379" type="int" />
		<constructor-arg index="3" value="300000" type="int" />
		<constructor-arg index="4" value="netsnapredis" />
	</bean>
应该是没有配置config的原因,看了下文档,config好想是必须参数,通过上面的配置可以直接链接上了。。。 唉,没砸用过jedis,正在学习中==
进退维谷 2017-05-26
  • 打赏
  • 举报
回复
我是这样配的,你看看有没有帮助。 <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"> <property name="maxIdle" value="${redis.maxIdle}" /> <property name="maxWaitMillis" value="1000" /> <property name="maxTotal" value="${redis.maxTotal}" /> </bean> <bean id="jedisPool" class="redis.clients.jedis.JedisPool"> <constructor-arg index="0" ref="jedisPoolConfig" /> <constructor-arg index="1" value="${redis.host}" /> <constructor-arg index="2" value="${redis.port}" /> <constructor-arg index="3" value="${redis.timeout}" /> <constructor-arg index="4" value="${redis.password}" /> </bean>
HinanaiTenshi 2017-05-26
  • 打赏
  • 举报
回复
如果一定要用JedisPool,请配置只有host一个参数的构造。 它的host字符串是一个完整的uri对象,密码直接戴在uri字符串里。
qq_33886281 2017-05-26
  • 打赏
  • 举报
回复
 <property name="password" value="yourpassword"/>
我项目一般配的是connectionfactory
ITnoLove 2017-05-26
  • 打赏
  • 举报
回复
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jedisServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private jedis.JedisClient service.primary.impl.JedisServiceImpl.jedisClient; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jedisClientPool': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private redis.clients.jedis.JedisPool jedis.JedisClientPool.jedisPool; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jedisPool' defined in class path resource [redis/applicationContext-redis.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities) ..... Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private jedis.JedisClient service.primary.impl.JedisServiceImpl.jedisClient; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jedisClientPool': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private redis.clients.jedis.JedisPool jedis.JedisClientPool.jedisPool; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jedisPool' defined in class path resource [redis/applicationContext-redis.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
ITnoLove 2017-05-26
  • 打赏
  • 举报
回复
引用 1 楼 qq_33886281 的回复:
<constructor-arg name="password" value="yourpassword"></constructor-arg>
不行,加上之后直接导致:Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jedisServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private jedis.JedisClient service.primary.impl.JedisServiceImpl.jedisClient; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jedisClientPool': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private redis.clients.jedis.JedisPool jedis.JedisClientPool.jedisPool; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jedisPool' defined in class path resource [redis/applicationContext-redis.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private jedis.JedisClient service.primary.impl.JedisServiceImpl.jedisClient; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jedisClientPool': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private redis.clients.jedis.JedisPool jedis.JedisClientPool.jedisPool; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jedisPool' defined in class path resource [redis/applicationContext-redis.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
qq_33886281 2017-05-26
  • 打赏
  • 举报
回复
<constructor-arg name="password" value="yourpassword"></constructor-arg>

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧