2012-02-13 105 views
0

有點急請幫忙!Spring ActiveMQ問題

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> 

回答

1

請發表您的Spring配置的詳細信息(XML文件)。現在只有從日誌中可以看出,你正在嘗試將字符串connectionFactory注入。請確保你定義了一個ID爲connectionFactory的bean,它應該是javax.jms.ConnectionFactory,然後用它來注入。

請發佈xml配置。這將有助於進一步調試該問題。

編輯

根據您輸入,

我沒有看到定義爲<property name="connectionFactory" ...任何地方的bean。你也提到它在其他一些環境上的工作。請檢查哪個xml文件包含此bean的定義,並確保該文件在您發佈的xml中隨Spring一起加載。

+0

添加的xml文件 – MozenRath 2012-02-13 07:17:20

+0

編輯根據您的輸入我的回答。 – Santosh 2012-02-13 07:49:07

+0

這兩個環境下的xml文件是相同的 – MozenRath 2012-02-13 07:51:09

3

你爲什麼不注射任何東西到connectionFactory屬性:

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

事情是,我們有一套產品,這是由另一個產品發送的,我不能改變XML。這適用於我的同事設置的其他設置,但不適用於我的設置。不知道爲什麼。 plz help – MozenRath 2012-02-13 07:26:37

+0

@MozenRath:我很確定''不適用於任何設置,只需查看API即可。你確定你的隊友使用相同的配置文件嗎? – 2012-02-13 07:54:45

+0

我很確定。 – MozenRath 2012-02-13 07:55:52