【问题标题】:Spring ActiveMQ IssueSpring ActiveMQ 问题
【发布时间】:2012-02-13 15:48:51
【问题描述】:

有点急,请帮忙!

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>

【问题讨论】:

    标签: java spring spring-security activemq spring-jms


    【解决方案1】:

    你为什么不向connectionFactory 属性注入任何东西:

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

    这必须改成:

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

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

    amqConnectionFactory factory 可以定义如下:

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

    【讨论】:

    • 问题是,我们有一套产品,这是由另一个产品发送的,我无法更改 xml。这适用于我同事的其他一些设置,但不适用于我的。不知道为什么。请帮助
    • @MozenRath:我很确定&lt;property name="connectionFactory" value=""/&gt; 不会在任何设置上工作,只需查看 API。你确定你的队友使用的是同一个配置文件吗?
    • 我在这里找不到问题。所以我切换到该产品的旧版本,但该版本也有相同的 connectionfactory 条目。但是,它现在可以工作。
    【解决方案2】:

    请发布您的弹簧配置详细信息(xml 文件)。现在,从日志中唯一可以明显看出的是,您正在尝试将属性 connectionFactory 作为字符串注入。请确保您定义了一个 id 为 connectionFactory 的 bean,它的类型应该是 javax.jms.ConnectionFactory,然后使用它来注入。

    请发布xml配置。这将有助于进一步调试问题。

    编辑

    根据您的输入,

    我在任何地方都没有看到定义为&lt;property name="connectionFactory" ... 的bean。您还提到它在其他一些环境中工作。请检查哪个 xml 文件包含此 bean 的定义,并确保该文件与您发布的 xml 一起由 spring 加载。

    【讨论】:

    • 根据您的输入编辑了我的答案。
    • 两种环境下的xml文件都是一样的
    • 我在这里找不到问题。所以我切换到该产品的旧版本,但该版本也有相同的 connectionfactory 条目。但是,它现在可以工作。
    • 输入你的意思是像&lt;property name="connectionFactory" value=""/&gt;这样的输入?
    猜你喜欢
    • 2013-08-01
    • 2015-01-22
    • 1970-01-01
    • 2017-11-26
    • 2013-12-10
    • 1970-01-01
    • 2016-04-27
    • 1970-01-01
    • 2012-06-10
    相关资源
    最近更新 更多