gpt4 book ai didi

java - Bean 属性 'channelIdentifierMap' 不可写或具有无效的 setter 方法

转载 作者:行者123 更新时间:2023-12-01 12:05:42 25 4
gpt4 key购买 nike

我正在使用 Spring 集成 4.0,并尝试创建一个有 2 个消息 channel 的 PayloadTypeRouter 对象 - 一个用于字符串有效负载,一个用于整数有效负载。我试图通过以下 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");
}}

具有以下配置:

<?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>

当我尝试运行它时,收到以下错误消息:

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; 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.

我注意到 AbstractMessageRouter 在 Spring Integration 4.0 版本中不包含映射 setter ,尽管它在以前的版本中包含映射 setter 。如何配置这种路由器?

最佳答案

我认为您不需要最后的 channel 定义。根据文档,您只需要:

<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: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>

关于java - Bean 属性 'channelIdentifierMap' 不可写或具有无效的 setter 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27634283/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com