我需要使用Camel ActiveMQ进行一些自定义。这样我就可以读取数据并将其推送到队列中。我有一个xml文件。项目构建没问题。执行程序时,我收到xml错误。
代码
public static void main(String[] args) {
ClassPathXmlApplicationContext app = new ClassPathXmlApplicationContext(
"config/my.xml");
System.out.println("reading done");
}
my.xml
<?xml version="1.0"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:util="http://www.springframework.org/schema/util" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring" xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd
http://www.springframework.org/schema/osgi-compendium
http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="tcp://localhost:61616" />
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="timer://MyTimer?fixedRate=true&period=4000" />
<setBody>
<constant>Hello World!</constant>
</setBody>
<to uri="activemq:camel.timer" />
</route>
<route>
<from uri="activemq:camel.timer" />
<to uri="file:C:/temp/sandpit/timer" />
</route>
</camelContext>
</beans>
错误
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Failed to create the JAXB binder; nested exception is javax.xml.bind.JAXBException: Provider com.sun.xml.internal.bind.v2.ContextFactory could not be instantiated: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "{http://camel.apache.org/schema/spring}propertyDefinition". Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:
at org.apache.camel.model.config.PropertyDefinition
at private java.util.List org.apache.camel.model.config.PropertiesDefinition.properties
at org.apache.camel.model.config.PropertiesDefinition
at private org.apache.camel.model.config.PropertiesDefinition org.apache.camel.spring.CamelContextFactoryBean.properties
at org.apache.camel.spring.CamelContextFactoryBean
this problem is related to the following location:
at org.apache.camel.model.PropertyDefinition
at private java.util.List org.apache.camel.core.xml.AbstractCamelEndpointFactoryBean.properties
at org.apache.camel.core.xml.AbstractCamelEndpointFactoryBean
at org.apache.camel.spring.CamelEndpointFactoryBean
at private java.util.List org.apache.camel.spring.CamelContextFactoryBean.endpoints
at org.apache.camel.spring.CamelContextFactoryBean
- with linked exception:
[com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "{http://camel.apache.org/schema/spring}propertyDefinition". Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:
at org.apache.camel.model.config.PropertyDefinition
at private java.util.List org.apache.camel.model.config.PropertiesDefinition.properties
at org.apache.camel.model.config.PropertiesDefinition
at private org.apache.camel.model.config.PropertiesDefinition org.apache.camel.spring.CamelContextFactoryBean.properties
at org.apache.camel.spring.CamelContextFactoryBean
this problem is related to the following location:
at org.apache.camel.model.PropertyDefinition
at private java.util.List org.apache.camel.core.xml.AbstractCamelEndpointFactoryBean.properties
at org.apache.camel.core.xml.AbstractCamelEndpointFactoryBean
at org.apache.camel.spring.CamelEndpointFactoryBean
at private java.util.List org.apache.camel.spring.CamelContextFactoryBean.endpoints
at org.apache.camel.spring.CamelContextFactoryBean
]
at org.apache.camel.spring.handler.CamelNamespaceHandler$CamelContextBeanDefinitionParser.doParse(CamelNamespaceHandler.java:305)
at org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser.parseInternal(AbstractSingleBeanDefinitionParser.java:85)
at org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.parse(AbstractBeanDefinitionParser.java:59)
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1438)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1428)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:185)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.ambika.testmq.ReadDataFromTCPPort.main(ReadDataFromTCPPort.java:8)
Caused by: javax.xml.bind.JAXBException: Provider com.sun.xml.internal.bind.v2.ContextFactory could not be instantiated: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "{http://camel.apache.org/schema/spring}propertyDefinition". Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:
at org.apache.camel.model.config.PropertyDefinition
at private java.util.List org.apache.camel.model.config.PropertiesDefinition.properties
at org.apache.camel.model.config.PropertiesDefinition
at private org.apache.camel.model.config.PropertiesDefinition org.apache.camel.spring.CamelContextFactoryBean.properties
at org.apache.camel.spring.CamelContextFactoryBean
this problem is related to the following location:
at org.apache.camel.model.PropertyDefinition
at private java.util.List org.apache.camel.core.xml.AbstractCamelEndpointFactoryBean.properties
at org.apache.camel.core.xml.AbstractCamelEndpointFactoryBean
at org.apache.camel.spring.CamelEndpointFactoryBean
at private java.util.List org.apache.camel.spring.CamelContextFactoryBean.endpoints
at org.apache.camel.spring.CamelContextFactoryBean
- with linked exception:
[com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "{http://camel.apache.org/schema/spring}propertyDefinition". Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:
at org.apache.camel.model.config.PropertyDefinition
at private java.util.List org.apache.camel.model.config.PropertiesDefinition.properties
at org.apache.camel.model.config.PropertiesDefinition
at private org.apache.camel.model.config.PropertiesDefinition org.apache.camel.spring.CamelContextFactoryBean.properties
at org.apache.camel.spring.CamelContextFactoryBean
this problem is related to the following location:
at org.apache.camel.model.PropertyDefinition
at private java.util.List org.apache.camel.core.xml.AbstractCamelEndpointFactoryBean.properties
at org.apache.camel.core.xml.AbstractCamelEndpointFactoryBean
at org.apache.camel.spring.CamelEndpointFactoryBean
at private java.util.List org.apache.camel.spring.CamelContextFactoryBean.endpoints
at org.apache.camel.spring.CamelContextFactoryBean
]
at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
at javax.xml.bind.ContextFinder.find(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at org.apache.camel.spring.handler.CamelNamespaceHandler.createJaxbContext(CamelNamespaceHandler.java:188)
at org.apache.camel.spring.handler.CamelNamespaceHandler.getJaxbContext(CamelNamespaceHandler.java:175)
at org.apache.camel.spring.handler.CamelNamespaceHandler$CamelContextBeanDefinitionParser.doParse(CamelNamespaceHandler.java:303)
... 24 more
Caused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "{http://camel.apache.org/schema/spring}propertyDefinition". Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:
at org.apache.camel.model.config.PropertyDefinition
at private java.util.List org.apache.camel.model.config.PropertiesDefinition.properties
at org.apache.camel.model.config.PropertiesDefinition
at private org.apache.camel.model.config.PropertiesDefinition org.apache.camel.spring.CamelContextFactoryBean.properties
at org.apache.camel.spring.CamelContextFactoryBean
this problem is related to the following location:
at org.apache.camel.model.PropertyDefinition
at private java.util.List org.apache.camel.core.xml.AbstractCamelEndpointFactoryBean.properties
at org.apache.camel.core.xml.AbstractCamelEndpointFactoryBean
at org.apache.camel.spring.CamelEndpointFactoryBean
at private java.util.List org.apache.camel.spring.CamelContextFactoryBean.endpoints
at org.apache.camel.spring.CamelContextFactoryBean
at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown Source)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
... 31 more
任何人都可以帮助我吗?提前谢谢
答案 0 :(得分:0)
尝试删除无关的命名空间作为起点。
将您的beans标记更改为
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
答案 1 :(得分:0)
再次详细说明@ user940782的评论,以免错过答案。
我使用嵌入式Activemq来部署基于Camel的应用程序。 我的Activemq v5.10.1使用Camel v2.13.1 我的骆驼应用程序使用的是v2.16.0
根据评论,我将应用程序中的Camel版本更改为2.13.1 问题得到了解决。