spring boot 配置redis 报错 NOAUTH Authentication required

yj327243832a 2016-08-25 05:58:10
spring boot 配置redis报错NOAUTH Authentication required

配置文件application.properties
# REDIS (RedisProperties)
# Redis\u6570\u636E\u5E93\u7D22\u5F15\uFF08\u9ED8\u8BA4\u4E3A0\uFF09
spring.redis.database=0
# Redis\u670D\u52A1\u5668\u5730\u5740
spring.redis.host=127.0.0.1
# Redis\u670D\u52A1\u5668\u8FDE\u63A5\u7AEF\u53E3
spring.redis.port=6379
# Redis\u670D\u52A1\u5668\u8FDE\u63A5\u5BC6\u7801\uFF08\u9ED8\u8BA4\u4E3A\u7A7A\uFF09
spring.redis.password=foobared
# \u8FDE\u63A5\u6C60\u6700\u5927\u8FDE\u63A5\u6570\uFF08\u4F7F\u7528\u8D1F\u503C\u8868\u793A\u6CA1\u6709\u9650\u5236\uFF09
spring.redis.pool.max-active=8
# \u8FDE\u63A5\u6C60\u6700\u5927\u963B\u585E\u7B49\u5F85\u65F6\u95F4\uFF08\u4F7F\u7528\u8D1F\u503C\u8868\u793A\u6CA1\u6709\u9650\u5236\uFF09
spring.redis.pool.max-wait=-1
# \u8FDE\u63A5\u6C60\u4E2D\u7684\u6700\u5927\u7A7A\u95F2\u8FDE\u63A5
spring.redis.pool.max-idle=8
# \u8FDE\u63A5\u6C60\u4E2D\u7684\u6700\u5C0F\u7A7A\u95F2\u8FDE\u63A5
spring.redis.pool.min-idle=0
# \u8FDE\u63A5\u8D85\u65F6\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09
spring.redis.timeout=0



pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
</dependency>

</dependencies>



测试类
import com.didispace.domain.User;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;


@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(Application.class)
public class ApplicationTests {

@Autowired
private StringRedisTemplate stringRedisTemplate;

@Autowired
private RedisTemplate<String, User> redisTemplate;

@Test
public void test() throws Exception {

// 保存字符串
stringRedisTemplate.opsForValue().set("aaa", "111");
Assert.assertEquals("111", stringRedisTemplate.opsForValue().get("aaa"));

// 保存对象
// User user = new User("超人", 20);
// redisTemplate.opsForValue().set(user.getUsername(), user);
//
// user = new User("蝙蝠侠", 30);
// redisTemplate.opsForValue().set(user.getUsername(), user);
//
// user = new User("蜘蛛侠", 40);
// redisTemplate.opsForValue().set(user.getUsername(), user);
//
// Assert.assertEquals(20, redisTemplate.opsForValue().get("超人").getAge().longValue());
// Assert.assertEquals(30, redisTemplate.opsForValue().get("蝙蝠侠").getAge().longValue());
// Assert.assertEquals(40, redisTemplate.opsForValue().get("蜘蛛侠").getAge().longValue());

}

}


debug发现RedisTemplate对象中的信息不是我配置的内容,我配置的是127.0.0.1端口但是读取到的是localhost,我配置了秘密但是读取到密码是null
...全文
4779 5 打赏 收藏 举报
写回复
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_41303271 2019-04-24
  • 打赏
  • 举报
回复
你好,为什么我在用redisTemplate.opsForValue().set(key, value, 60, TimeUnit.HOURS);的时候回报错:
weixin_41303271 2019-04-24
  • 打赏
  • 举报
回复
你好为什么我在用redisTemplate.opsForValue().set(key, value, 60, TimeUnit.HOURS);的时候回报错:
  • 打赏
  • 举报
回复
我也遇到了这个问题

这样解决就好了
SuperLGX 2017-04-23
  • 打赏
  • 举报
回复
我也碰到这样的情况了,我在application.properties 中也配置了redis 的密码但是容器好像没有读取到,或者没有自动配置
小崔爱读书 2016-12-05
  • 打赏
  • 举报
回复
redis拿来做缓存的吗?
发帖
Java EE

6.7w+

社区成员

J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
帖子事件
创建了帖子
2016-08-25 05:58
社区公告
暂无公告