获取BeanCreationException当试图添加杰克逊库 [英] Get BeanCreationException when try to add Jackson Library

查看:162
本文介绍了获取BeanCreationException当试图添加杰克逊库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个传递映射到骆驼和显示的值通过Log4J的控制台简单的Hello World例子。我想加入杰克逊库到我的骆驼的applicationContext.xml

拓展这个例子来呈现这个地图JSON

首先,我尝试添加下面的XML标记的applicationContext.xml我(于指定
http://camel.apache.org/json.html 下的春DSL使用JSON )

 <骆驼:dataFormats>
    <骆驼:JSON ID =杰克库=禅师/>
< /骆驼:dataFormats>

但是,当我加入到我的applicationContext.xml,并运行我的Java code我得到以下XmlBeanDefinitionStoreException消息:

  CVC-复杂type.2.4.a:无效的含量被发现开始元素dataFormats。其中一个{http://camel.apache.org/schema/
 春天:路线}'的预期。

移动这些标记中或我的camelContext之外产生同样的错误(只是一个URL时的camelContext内的长列表)。

有没有别的东西我需要在我的applicationContext.xml来指定?

下面是我当前的applicationContext.xml:

更新:下面的XML现在的作品。不得不移动dataFormats XML标记的位置。

 <?XML版本=1.0编码=UTF-8&GT?;
<豆的xmlns =htt​​p://www.springframework.org/schema/beans
     XMLNS:XSI =htt​​p://www.w3.org/2001/XMLSchema-instance的xmlns:骆驼=htt​​p://camel.apache.org/schema/spring
的xmlns:上下文=htt​​p://www.springframework.org/schema/context
的xmlns:UTIL =htt​​p://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\"><豆
    类=org.springframework.context.annotation.CommonAnnotationBeanPostProcessor/>
<背景:组件扫描基包=样品/>
<背景:注解配置/><骆驼:camelContext ID =HelloWorldContext><骆驼:dataFormats>
  <骆驼:JSON ID =杰克库=禅师/>
< /骆驼:dataFormats><骆驼:路线>     <骆驼:从
          URI =?定时器://hello.world.request.timer固定利率=真放大器;放大器;周期= 10000/>
     <骆驼:到URI =?日志:hello.world.request水平= INFO SHOWALL =真正的/>
     <骆驼:豆REF =的HelloWorld/>
     <骆驼:到URI =日志:?hello.world.response水平= INFO SHOWALL =真正的/>
< /骆驼:路线>< /骆驼:camelContext><豆的id =JMS级=org.apache.activemq.camel.component.ActiveMQComponent>
   <属性名=配置REF =jmsConfig/>
< /豆><豆的id =jmsConfig级=org.apache.camel.component.jms.JmsConfiguration>
  <属性名=connectionFactory的REF =jmsConnectionFactory/>
  <属性名=交易VALUE =FALSE/>
  <属性名=concurrentConsumers值=1/>
< /豆><豆的id =jmsConnectionFactory级=org.apache.activemq.ActiveMQConnectionFactory>
  <属性名=brokerURLVALUE =VM:// localhost的/>
  <属性名=redeliveryPolicyREF =redeliveryPolicy/>
  <属性名=prefetchPolicyREF =prefetchPolicy/>
< /豆><豆的id =prefetchPolicy级=org.apache.activemq.ActiveMQ prefetchPolicy>
  <属性名=队列prefetchVALUE =5/>
< /豆><豆的id =redeliveryPolicy级=org.apache.activemq.RedeliveryPolicy>
  <属性名=maximumRedeliveries值=1/>
  <属性名=backOffMultiplierVALUE =2/>
  <属性名=initialRedeliveryDelay值=2000/>
  <属性名=useExponentialBackOffVALUE =真/>
< /豆>< /豆>


解决方案

的DateFormats JSON 元素是骆驼的一部分命名空间。你需要指定

 <骆驼:dataFormats>
    <骆驼:JSON ID =杰克库=禅师/>
< /骆驼:dataFormats>

I have a simple Hello World example that passes a Map to Camel and displays the values to the console via Log4J. I want to expand this example to render this map in JSON by adding the Jackson library to my Camel applicationContext.xml

First I tried adding the following XML tags to my applicationContext.xml (as specified at http://camel.apache.org/json.html under "Using JSON in Spring DSL")

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

But when I add this to my applicationContext.xml, and run my Java code I get the following XmlBeanDefinitionStoreException message:

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. 

Moving these tags inside or outside of my camelContext yields the same error (just a longer list of URLs when inside the camelContext).

Is there something else I need to specify in my ApplicationContext.xml?

Here is my current applicationContext.xml:

UPDATED: The following xml now works. Had to move the location of the dataFormats XML tags.

<?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. You need to specify that

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

这篇关于获取BeanCreationException当试图添加杰克逊库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆