camel中的JaxB编组
我不熟悉java中的ApacheCamel和Jax b概念。 我有一个驼峰队列中的java对象列表。我想用JAVSDSL(不使用spring)将其打包成xml。 有谁能指导我这样做吗 我有下面的POJO课程camel中的JaxB编组,jaxb,apache-camel,marshalling,Jaxb,Apache Camel,Marshalling,我不熟悉java中的ApacheCamel和Jax b概念。 我有一个驼峰队列中的java对象列表。我想用JAVSDSL(不使用spring)将其打包成xml。 有谁能指导我这样做吗 我有下面的POJO课程 public class MyPojo { private int groupId; private int memberId; private String details; public int getgroupId() { return groupId; } public vo
public class MyPojo {
private int groupId;
private int memberId;
private String details;
public int getgroupId() {
return groupId;
}
public void setgroupId(int groupId) {
this.groupId = groupId;
}
public int getMemberId() {
return memberId;
}
public void setMemberId(int memberId) {
this.memberId = memberId;
}
public String getdetails() {
return details;
}
public void setdetails(String details) {
this.details = details;
}}
下面是我的jaxb实现的camel代码
JaxbDataFormat jaxbMarshal = new JaxbDataFormat();
jaxbMarshal.setContextPath("com.test");
jaxbMarshal.setPartClass("com.test.MyPojo");
from("direct:javaObjects") //this direct having the list of MYPojo Objects
.marshal(jaxbMarshal)
.to("src/output");
我遇到以下异常(我在类路径中为jaxb添加了maven依赖项)
在以下位置创建路由route4失败:>>>Marshal[org.apache.camel.model.dataformat。JaxbDataFormat@3feb2dda]我已经创建了jaxb.index文件(来自eclipse的新->文件)。文件的内容应该是注释类名
在我们的情况下,应该是这样
MyPojo
并且需要将其放置在上下文路径中。在我们的情况下,它应该放在
com.test位置
带注释的Pojo类是
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class MyPojo {
@XmlElement
private int groupId;
@XmlElement
private int memberId;
@XmlElement
private String details;
public int getgroupId() {
return groupId;
}
public void setgroupId(int groupId) {
this.groupId = groupId;
}
public int getMemberId() {
return memberId;
}
public void setMemberId(int memberId) {
this.memberId = memberId;
}
public String getdetails() {
return details;
}
public void setdetails(String details) {
this.details = details;
}}
您可以将pojo与一些注释一起使用:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name="MY-POJO")
@XmlType(propOrder = {"groupId", "memberId", "details"})
public class MyPojo {
@XmlElement(name = "groupId")
private int groupId;
@XmlElement(name = "memberId")
private int memberId;
@XmlElement(name = "details")
private String details;
public int getgroupId() {
return groupId;
}
public void setgroupId(int groupId) {
this.groupId = groupId;
}
public int getMemberId() {
return memberId;
}
public void setMemberId(int memberId) {
this.memberId = memberId;
}
public String getdetails() {
return details;
}
public void setdetails(String details) {
this.details = details;
}}
您的应用程序的类路径中是否存在camel-jaxb组件的依赖关系?是的,您需要将camel-jaxb添加到类路径中,还需要将jaxb注释添加到POJO类中,并添加jaxb.index
文件。您可以在internet上搜索什么是jaxb.index
文件。谢谢@ClausIbsen。我已经注释过了,它工作得很好
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name="MY-POJO")
@XmlType(propOrder = {"groupId", "memberId", "details"})
public class MyPojo {
@XmlElement(name = "groupId")
private int groupId;
@XmlElement(name = "memberId")
private int memberId;
@XmlElement(name = "details")
private String details;
public int getgroupId() {
return groupId;
}
public void setgroupId(int groupId) {
this.groupId = groupId;
}
public int getMemberId() {
return memberId;
}
public void setMemberId(int memberId) {
this.memberId = memberId;
}
public String getdetails() {
return details;
}
public void setdetails(String details) {
this.details = details;
}}