[英]Bean property 'channelIdentifierMap' is not writable or has an invalid setter method
I'm using Spring integration 4.0 and I tried to create a payloadTypeRouter object that has 2 message channels - one for String payloads and one for Integer payloads. 我使用的是Spring Integration 4.0,并尝试创建一个有效负载类型路由对象,该对象具有2个消息通道-一个用于字符串有效负载,一个用于整数有效负载。 I'm trying to do so by the following java code:
我正在尝试通过以下Java代码来做到这一点:
package MessageExamples;
import org.springframework.messaging.Message;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.router.PayloadTypeRouter;
public class Test {
public static void main(String[] args) {
QueueChannel q_channel1=new QueueChannel();
QueueChannel q_channel2=new QueueChannel();
ApplicationContext ctx= new ClassPathXmlApplicationContext("SpringIntegration.xml");
PayloadTypeRouter r= (PayloadTypeRouter) ctx.getBean("payloadTypeRouter");
}}
With the following configuration: 使用以下配置:
<?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:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd">
<bean id="payloadTypeRouter"
class="org.springframework.integration.router.PayloadTypeRouter">
<property name="channelIdentifierMap">
<map>
<entry key="java.lang.String" value-ref="stringChannel"/>
<entry key="java.lang.Integer" value-ref="integerChannel"/>
</map>
</property>
</bean>
<int:channel id="stringChannel"/>
<int:channel id="integerChannel"/>
</beans>
When I try to run it I get the following error message: 当我尝试运行它时,出现以下错误消息:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'payloadTypeRouter' defined in class path resource [SpringIntegration.xml]: Error setting property values;
线程“主”中的异常org.springframework.beans.factory.BeanCreationException:创建在类路径资源[SpringIntegration.xml]中定义的名称为'payloadTypeRouter'的bean时出错:设置属性值时出错; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'channelIdentifierMap' of bean class [org.springframework.integration.router.PayloadTypeRouter]: Bean property 'channelIdentifierMap' is not writable or has an invalid setter method.
嵌套的异常是org.springframework.beans.NotWritablePropertyException:Bean类[org.springframework.integration.router.PayloadTypeRouter]的无效属性'channelIdentifierMap':Bean属性'channelIdentifierMap'是不可写的或具有无效的setter方法。
I've noticed that AbstractMessageRouter doesn't contain a map setter in Spring Integration version 4.0 although it has one in previous versions. 我注意到,AbstractMessageRouter在Spring Integration版本4.0中不包含映射设置器,尽管它在以前的版本中具有一个映射器。 How can I configurate this kind of router?
如何配置这种路由器?
I think that you don't need the last channels definitions. 我认为您不需要最后一个渠道定义。 According to the docs, you only need:
根据文档,您只需要:
<bean id="payloadTypeRouter"
class="org.springframework.integration.router.PayloadTypeRouter">
<property name="channelIdentifierMap">
<map>
<entry key="java.lang.String" value-ref="stringChannel"/>
<entry key="java.lang.Integer" value-ref="integerChannel"/>
</map>
</property>
</bean>
Or, an equivalent definition: 或者,一个等效的定义:
<int:payload-type-router input-channel="routingChannel">
<int:mapping type="java.lang.String" channel="stringChannel" />
<int:mapping type="java.lang.Integer" channel="integerChannel" />
</int:payload-type-router>
The property was renamed to channelMapping
several years ago (in 2.1); 几年前,该属性已重命名为
channelMapping
(在2.1中); I have opened a JIRA Issue to fix the documentation. 我已经打开JIRA问题来修复文档。
Thanks for pointing this out. 感谢您指出了这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.