gpt4 book ai didi

java - 尝试添加 Jackson 库时出现 BeanCreationException

转载 作者:行者123 更新时间:2023-11-30 04:12:22 24 4
gpt4 key购买 nike

我有一个简单的 Hello World 示例,它将 Map 传递给 Camel 并通过 Log4J 将值显示到控制台。我想通过将 Jackson 库添加到我的 Camel applicationContext.xml 来扩展此示例,以 JSON 格式呈现此 map

首先,我尝试将以下 XML 标记添加到我的 applicationContext.xml 中(如指定的那样) http://camel.apache.org/json.html在“在 Spring DSL 中使用 JSON”下)

<camel:dataFormats>
<camel:json id="jack" library="Jackson"/>
</camel:dataFormats>

但是当我将其添加到 applicationContext.xml 并运行 Java 代码时,我收到以下 XmlBeanDefinitionStoreException 消息:

cvc-complex-type.2.4.a: Invalid content was found starting with element 'dataFormats'.     One of '{"http://camel.apache.org/schema/
spring":route}' is expected.

将这些标签移动到camelContext内部或外部都会产生相同的错误(只是在camelContext内部出现更长的URL列表)。

我还需要在 ApplicationContext.xml 中指定其他内容吗?

这是我当前的 applicationContext.xml:

更新:以下 xml 现在可以使用。必须移动 dataFormats 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:camel="http://camel.apache.org/schema/spring"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<bean
class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />
<context:component-scan base-package="sample" />
<context:annotation-config />

<camel:camelContext id="HelloWorldContext">

<camel:dataFormats>
<camel:json id="jack" library="Jackson"/>
</camel:dataFormats>

<camel:route>

<camel:from
uri="timer://hello.world.request.timer?fixedRate=true&amp;period=10000" />
<camel:to uri="log:hello.world.request?level=INFO?showAll=true" />
<camel:bean ref="helloWorld" />
<camel:to uri="log:hello.world.response?level=INFO?showAll=true" />
</camel:route>

</camel:camelContext>

<bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="jmsConfig" />
</bean>

<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="jmsConnectionFactory" />
<property name="transacted" value="false" />
<property name="concurrentConsumers" value="1" />
</bean>

<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost" />
<property name="redeliveryPolicy" ref="redeliveryPolicy" />
<property name="prefetchPolicy" ref="prefetchPolicy" />
</bean>

<bean id="prefetchPolicy" class="org.apache.activemq.ActiveMQPrefetchPolicy">
<property name="queuePrefetch" value="5" />
</bean>

<bean id="redeliveryPolicy" class="org.apache.activemq.RedeliveryPolicy">
<property name="maximumRedeliveries" value="1" />
<property name="backOffMultiplier" value="2" />
<property name="initialRedeliveryDelay" value="2000" />
<property name="useExponentialBackOff" value="true" />
</bean>

</beans>

最佳答案

The dateFormats and json elements are part of the camel namespace.您需要指定

<camel:dataFormats>
<camel:json id="jack" library="Jackson"/>
</camel:dataFormats>

关于java - 尝试添加 Jackson 库时出现 BeanCreationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19306106/

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