Invalid property 'sentinels' of bean class redis spring 错误修改
/*
* Copyright 2014-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection; import static org.springframework.util.Assert.*;
import static org.springframework.util.StringUtils.*; import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set; import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.util.StringUtils; /**
* Configuration class used for setting up {@link RedisConnection} via {@link RedisConnectionFactory} using connecting
* to <a href="http://redis.io/topics/sentinel">Redis Sentinel(s)</a>. Useful when setting up a high availability Redis
* environment.
*
* @author Christoph Strobl
* @author Thomas Darimont
* @since 1.4
*/
public class RedisSentinelConfiguration { private static final String REDIS_SENTINEL_MASTER_CONFIG_PROPERTY = "spring.redis.sentinel.master";
private static final String REDIS_SENTINEL_NODES_CONFIG_PROPERTY = "spring.redis.sentinel.nodes"; private NamedNode master;
private Set<RedisNode> sentinels; /**
* Creates new {@link RedisSentinelConfiguration}.
*/
public RedisSentinelConfiguration() {
this(new MapPropertySource("RedisSentinelConfiguration", Collections.<String, Object> emptyMap()));
} /**
* Creates {@link RedisSentinelConfiguration} for given hostPort combinations.
*
* <pre>
* sentinelHostAndPorts[0] = 127.0.0.1:23679
* sentinelHostAndPorts[1] = 127.0.0.1:23680
* ...
*
* <pre>
*
* @param sentinelHostAndPorts must not be {@literal null}.
* @since 1.5
*/
public RedisSentinelConfiguration(String master, Set<String> sentinelHostAndPorts) {
this(new MapPropertySource("RedisSentinelConfiguration", asMap(master, sentinelHostAndPorts)));
} /**
* Creates {@link RedisSentinelConfiguration} looking up values in given {@link PropertySource}.
*
* <pre>
* <code>
* spring.redis.sentinel.master=myMaster
* spring.redis.sentinel.nodes=127.0.0.1:23679,127.0.0.1:23680,127.0.0.1:23681
* </code>
* </pre>
*
* @param propertySource must not be {@literal null}.
* @since 1.5
*/
public RedisSentinelConfiguration(PropertySource<?> propertySource) { notNull(propertySource, "PropertySource must not be null!"); this.sentinels = new LinkedHashSet<RedisNode>(); if (propertySource.containsProperty(REDIS_SENTINEL_MASTER_CONFIG_PROPERTY)) {
this.setMaster(propertySource.getProperty(REDIS_SENTINEL_MASTER_CONFIG_PROPERTY).toString());
} if (propertySource.containsProperty(REDIS_SENTINEL_NODES_CONFIG_PROPERTY)) {
appendSentinels(commaDelimitedListToSet(propertySource.getProperty(REDIS_SENTINEL_NODES_CONFIG_PROPERTY)
.toString()));
}
} /**
* Set {@literal Sentinels} to connect to.
*
* @param sentinels must not be {@literal null}.
*/
public void setSentinels(Iterable<RedisNode> sentinels) { notNull(sentinels, "Cannot set sentinels to 'null'."); this.sentinels.clear(); for (RedisNode sentinel : sentinels) {
addSentinel(sentinel);
}
}
public void setSentinels(Set<RedisNode> sentinels) { notNull(sentinels, "Cannot set sentinels to 'null'."); this.sentinels.clear(); for (RedisNode sentinel : sentinels) {
addSentinel(sentinel);
}
} /**
* Returns an {@link Collections#unmodifiableSet(Set)} of {@literal Sentinels}.
*
* @return {@link Set} of sentinels. Never {@literal null}.
*/
public Set<RedisNode> getSentinels() {
return Collections.unmodifiableSet(sentinels);
} /**
* Add sentinel.
*
* @param sentinel must not be {@literal null}.
*/
public void addSentinel(RedisNode sentinel) { notNull(sentinel, "Sentinel must not be 'null'.");
this.sentinels.add(sentinel);
} /**
* Set the master node via its name.
*
* @param name must not be {@literal null}.
*/
public void setMaster(final String name) { notNull(name, "Name of sentinel master must not be null.");
setMaster(new NamedNode() { @Override
public String getName() {
return name;
}
});
} /**
* Set the master.
*
* @param master must not be {@literal null}.
*/
public void setMaster(NamedNode master) { notNull("Sentinel master node must not be 'null'.");
this.master = master;
} /**
* Get the {@literal Sentinel} master node.
*
* @return
*/
public NamedNode getMaster() {
return master;
} /**
* @see #setMaster(String)
* @param master
* @return
*/
public RedisSentinelConfiguration master(String master) {
this.setMaster(master);
return this;
} /**
* @see #setMaster(NamedNode)
* @param master
* @return
*/
public RedisSentinelConfiguration master(NamedNode master) {
this.setMaster(master);
return this;
} /**
* @see #addSentinel(RedisNode)
* @param sentinel
* @return
*/
public RedisSentinelConfiguration sentinel(RedisNode sentinel) {
this.addSentinel(sentinel);
return this;
} /**
* @see #sentinel(RedisNode)
* @param host
* @param port
* @return
*/
public RedisSentinelConfiguration sentinel(String host, Integer port) {
return sentinel(new RedisNode(host, port));
} private void appendSentinels(Set<String> hostAndPorts) { for (String hostAndPort : hostAndPorts) {
addSentinel(readHostAndPortFromString(hostAndPort));
}
} private RedisNode readHostAndPortFromString(String hostAndPort) { String[] args = split(hostAndPort, ":"); notNull(args, "HostAndPort need to be seperated by ':'.");
isTrue(args.length == 2, "Host and Port String needs to specified as host:port");
return new RedisNode(args[0], Integer.valueOf(args[1]).intValue());
} /**
* @param master must not be {@literal null} or empty.
* @param sentinelHostAndPorts must not be {@literal null}.
* @return
*/
private static Map<String, Object> asMap(String master, Set<String> sentinelHostAndPorts) { hasText(master, "Master address must not be null or empty!");
notNull(sentinelHostAndPorts, "SentinelHostAndPorts must not be null!"); Map<String, Object> map = new HashMap<String, Object>();
map.put(REDIS_SENTINEL_MASTER_CONFIG_PROPERTY, master);
map.put(REDIS_SENTINEL_NODES_CONFIG_PROPERTY, StringUtils.collectionToCommaDelimitedString(sentinelHostAndPorts)); return map;
}
}
Invalid property 'sentinels' of bean class redis ,spring 集成redis时报的错,集成配置如下,
<!-- redis配置 -->
<bean id="redisSentinelConfiguration"
class="org.springframework.data.redis.connection.RedisSentinelConfiguration">
<property name="master">
<bean class="org.springframework.data.redis.connection.RedisNode">
<property name="name" value="${redis.sentinels.name}">
</property>
</bean>
</property>
<property name="sentinels">
<set>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg name="host" value="${redis.sentinels.ip1}" />
<constructor-arg name="port" value="${redis.sentinels.port1}" />
</bean>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg name="host" value="${redis.sentinels.ip2}" />
<constructor-arg name="port" value="${redis.sentinels.port2}" />
</bean>
</set>
</property>
</bean>
<!-- <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" >
<property name="hostName" value="${redis.hostName}"></property>
<property name="port" value="${redis.port}"></property>
<property name="password" value="${redis.password}"></property>
<property name="timeout" value="${redis.timeout}" />
<property name="usePool" value="true" />
<property name="poolConfig" ref="jedisPoolConfig" />
</bean> -->
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" >
<constructor-arg name="sentinelConfig" ref="redisSentinelConfiguration"></constructor-arg>
<property name="password" value="${redis.sentinels.password}"></property>
<constructor-arg name="poolConfig" ref="jedisPoolConfig"></constructor-arg>
</bean> <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="${redis.maxTotal}"></property>
<property name="maxIdle" value="${redis.maxIdle}"></property>
<property name="maxWaitMillis" value="${redis.maxWaitMillis}"></property>
<property name="testOnBorrow" value="${redis.testOnBorrow}"></property>
</bean> <bean id="stringRedisSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer" /> <!-- <bean id="jacksonJsonRedisSerializer" class="org.springframework.data.redis.serializer.JacksonJsonRedisSerializer" >
<constructor-arg type="java.lang.Class" value="java.lang.Object"/>
</bean> --> <bean id="jacksonJsonRedisSerializer" class="org.springframework.data.redis.serializer.JacksonJsonRedisSerializer" >
<constructor-arg type="java.lang.Class" value="java.lang.Object"/>
</bean> <bean id="jdkSerializationRedisSerializer" class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/> <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory"></property>
<property name="keySerializer" ref="stringRedisSerializer"/>
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer"/>
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
<value>classpath:redis.properties</value>
</list>
</property>
</bean>
redis 配置文件
#redis连接池配置
redis.maxTotal=300
redis.maxIdle=20
#读取超时
redis.maxWaitMillis=5000
redis.testOnBorrow=true #redis连接配置
redis.hostName=192.168.100.75
redis.port=6379
redis.password=desc@1997
#连接超时
redis.timeout=5000 #哨兵的配置
redis.sentinels.ip1=192.168.100.67
redis.sentinels.port1=26378 redis.sentinels.ip2=192.168.100.67
redis.sentinels.port2=26379 redis.sentinels.name=mymaster
redis.sentinels.password=lolaage_cache
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.5.0.RELEASE</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.6.2</version>
</dependency>
出现错误的原因是 spring用的3.1的版本,需要spring4的版本才不会报错,懒得升级版本,研究了一下,发现加个方法可以解决,
加个如下的类,RedisSentinelConfiguration ,如下的方法即可解决
public void setSentinels(Set<RedisNode> sentinels) {
notNull(sentinels, "Cannot set sentinels to 'null'.");
this.sentinels.clear();
for (RedisNode sentinel : sentinels) {
addSentinel(sentinel);
}
}
Invalid property 'sentinels' of bean class redis spring 错误修改的更多相关文章
- Invalid property 'url' of bean class [com.mchange.v2.c3p0.ComboPooledDataSource]
1.错误描述 INFO:2015-05-01 13:13:05[localhost-startStop-1] - Initializing c3p0-0.9.2.1 [built 20-March-2 ...
- Invalid property 'driver_class' of bean class
1.错误描述 INFO:2015-05-01 13:06:07[localhost-startStop-1] - Initializing c3p0-0.9.2.1 [built 20-March-2 ...
- Invalid property 'annotatedClasses' of bean class
Invalid property 'annotatedClasses' of bean class 在整合Hibernate和Spring时出现,Invalid property 'annotated ...
- Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'URIType' of bean class [com.alibaba.citrus.service.uribroker.uri.GenericURIBroker]
linux中的JDK为JDK8,tomcat为tomcat8 加入dubbo.war包 启动报错! Caused by: org.springframework.beans.factory.BeanC ...
- 使用springmvc时报错org.springframework.beans.NullValueInNestedPathException: Invalid property 'department' of bean class [com.atguigu.springmvc.crud.entities.Employee]:
使用springmvc时报错 org.springframework.beans.NullValueInNestedPathException: Invalid property 'departmen ...
- Initialization of bean failed; nested exception is org.springframework.beans.InvalidPropertyException: Invalid property 'dataSource' of bean class [com.liuyang.jdbc.PersonDao]: No property 'dataSource
这个错误是说我的启动失败了.这类问题要从配置文件中开始找原因,我用的是spring框架,所以我从application.中找的原因 然后对比路径,对比文件的命名和id,都没有问题,为什么会在启动的时候 ...
- Invalid property 'driverClassName' of bean class [com.mchange.v2.c3p0.ComboPooledDataSource]
spring配置文件中配置c3p0错误,错误原因在于c3p0连接池与DBCP连接池在驱动.连接.数据库用户名这些属性名称的差别
- Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'URIType' of bean class
查阅了资料原始JDK的问题.解决方法 1.重新安装JDK为1.7版本 2.修改配置 1.webx的依赖改为3.1.6版: <dependency> <groupId>com.a ...
- spring错误汇总
在学习spring过程中遇见了种种不同的异常错误,这里做了一下总结.希望遇见类似错误的同学们共勉一下. 1. 错误一 Error creating bean with name 'helloServi ...
随机推荐
- ajax的两种使用方式
一.Ajax概述 1.什么是同步,什么是异步 同步现象:客户端发送请求到服务器端,当服务器返回响应之前,客户端都处于等待 卡死状态 异步现象:客户端发送请求到服务器端,无论服务器是否返回响应,客户端都 ...
- cogs 466. [NOIP2009] 细胞分裂
466. [NOIP2009] 细胞分裂 ★★ 输入文件:cell.in 输出文件:cell.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] Hanks ...
- JDK1.7中的ThreadPoolExecutor源代码剖析
JDK1. 7中的ThreadPoolExecutor 线程池,顾名思义一个线程的池子,池子里存放了非常多能够复用的线程,假设不用线程池相似的容器,每当我们须要创建新的线程时都须要去new Threa ...
- CF 447B(DZY Loves Strings-贪心)
B. DZY Loves Strings time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 黑马day15 文件上传&apche的工具包
1.肯定要导入apche的jar包 2.要使用的类的介绍.. 2.1DiskFileItemFactory public DiskFileItemFactory(int sizeThreshold, ...
- SaltStack介绍——SaltStack是一种新的基础设施管理方法开发软件,简单易部署,可伸缩的足以管理成千上万的服务器,和足够快的速度控制,与他们交流
SaltStack介绍和架构解析 简介 SaltStack是一种新的基础设施管理方法开发软件,简单易部署,可伸缩的足以管理成千上万的服务器,和足够快的速度控制,与他们交流,以毫秒为单位.SaltSta ...
- ios问题bug收录——1
**[2713:59682] *** Assertion failure in -[MBProgressHUD show:], /Users/lu/Desktop/****/Pods/MBProgr ...
- 访问Storm ui界面,出现org.apache.storm.utils.NimbusLeaderNotFoundException: Could not find leader nimbus from seed hosts ["master"]. Did you specify a valid list of nimbus hosts for confi的问题解决(图文详解)
不多说,直接上干货! 前期博客 apache-storm-0.9.6.tar.gz的集群搭建(3节点)(图文详解) apache-storm-1.0.2.tar.gz的集群搭建(3节点)(图文详解)( ...
- Linux基础01
** 一些老生常谈的问题 一提起Linux,行业内无人不知<鸟哥私房菜>,就是放在胸口可以防弹的那种书,虽说经典.全面,但对于初学者而言,确实过于厚重,而且容易学着后边忘了前边,毕竟实际操 ...
- C# 分隔字符串成为字符串数组的方法(保留分隔符)
要求如下: source string: mmmmmmynameismickeym separator: m result string []: {"m", "m&quo ...