gpt4 book ai didi

java - Spring ActiveMQ 问题

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

有点紧急,请帮忙!

Why do I get IllegalArgumentException Cannot convert value of type String to required type Product, in Spring?

我已经读过这个问题,因为我遇到了类似的异常:

<Feb 13, 2012 11:55:39 AM IST> <Warning> <HTTP> <BEA-101162> <User defined listener org.springframework.web.context.ContextLoaderListener failed: org.springframework.beans.factory.BeanCreationExceptio
n: Error creating bean with name 'jmsTemplate' defined in class path resource [manager-security-audit.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchExc
eption: Failed to convert property value of type [java.lang.String] to required type [javax.jms.ConnectionFactory] for property 'connectionFactory'; nested exception is java.lang.IllegalArgumentExcept
ion: Cannot convert value of type [java.lang.String] to required type [javax.jms.ConnectionFactory] for property 'connectionFactory': no matching editors or conversion strategy found.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsTemplate' defined in class path resource [manager-security-audit.xml]: Initialization of bean failed; nested
exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [javax.jms.ConnectionFactory] for property 'connectionFactory
'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [javax.jms.ConnectionFactory] for property 'connectionFactory': no matching
editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
Truncated. see log file for complete stacktrace

我也看到了这个问题的答案,现在我的问题是:我如何知道我是否在定义参数时遇到类似的问题(我个人认为这不是这里的问题(只是直觉))?或者这是其他问题吗?

请帮忙

这是 xml 文件:

<?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:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/lang

http://www.springframework.org/schema/lang/spring-lang-2.0.xsd">
<bean id="auditListener" class="com.unica.manager.audit.AuditListener"/>
<bean id="auditEventDestination" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="audit.event.queue"/>
</bean>
<bean id="auditEventMessageConverter" class="com.unica.manager.audit.AuditEventMessageConverter"/>

<bean id="purePojoMdp" class="org.springframework.jms.listener.adapter.MessageListenerAdapter">
<property name="delegate" ref="AuditEventManager"/>
<property name="defaultListenerMethod" value="addAuditEvent"/>
<property name="messageConverter" ref="auditEventMessageConverter"/>
</bean>
<bean name="auditListenerContainer" class="org.springframework.jms.listener.SimpleMessageListenerContainer" lazy-init="true">
<property name="autoStartup" value="false"/>
<property name="connectionFactory" value=""/>
<property name="destination" ref="auditEventDestination"/>
<property name="messageListener" ref="purePojoMdp"/>
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate" depends-on="ConfigurationManager" >
<property name="connectionFactory" value=""/>
<property name="messageConverter" ref="auditEventMessageConverter"/>
</bean>
<bean id="audit" class="com.unica.manager.audit.Audit" >
<property name="jmsTemplate" ref="jmsTemplate"/>
<property name="enableQueuing" value="true"/>
<property name="auditEventManager" ref="AuditEventManager"/>
<property name="destination" ref="auditEventDestination"/>
</bean>

最佳答案

为什么不向 connectionFactory 属性中注入(inject)任何内容:

<property name="connectionFactory" value=""/>

这必须更改为:

<property name="connectionFactory" ref="amqConnectionFactory"/>

connectionFactory 属性的类型为 javax.jms.ConnectionFactory (参见:JmsAccessor.setConnectionFactory())。

amqConnectionFactory 工厂可以定义如下:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:amq="http://activemq.apache.org/schema/core"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

<amq:connectionFactory id="amqConnectionFactory" brokerURL="vm://localhost" />

</beans>

关于java - Spring ActiveMQ 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9256681/

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