java - 如何将 jaxb 打印到 java 对象到记录器中

标签 java apache jakarta-ee logging jaxb

您好,通过以下链接,我可以将 JAXB 转换为 java 对象,并使用以下语句在控制台中打印它。

http://www.mkyong.com/java/jaxb-hello-world-example/

jaxbMarshaller.marshal(customer, System.out);

但我想在记录器中打印输出。

例如)log.info(客户)或 log.debug(客户)

我正在使用 Apache log4j。有人知道吗??

最佳答案

下面是一种可能的方式..

Customer customer = new Customer();
//set customer attributes 
JAXBContext jc = JAXBContext.newInstance(Customer.class);
Marshaller marshaller = jc.createMarshaller();
StringWriter stringWriter = new StringWriter();
marshaller.marshal(customer, stringWriter );
log.info(stringWriter.toString());

关于java - 如何将 jaxb 打印到 java 对象到记录器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26139999/

相关文章:

java - 如何在 Play 框架单元测试中加载不同的插件?

apache - 使用 mod_proxy_ajp 时无限重定向?

java - JMS-分布式事务

java - Angular + Spring,$http 和 $location 获取项目名称

java - 大于 64 位的快速位掩码

apache - 运行Docker镜像时的“no such file or directory”

java - @PersistenceContext(unitName ="myPersistence") 无法启动我的 TomEE Web 服务器

java - 远程访问 Liferay 内容 给出异常 权限检查器未初始化

java - Scala 相当于 JavaScript 数组扩展

html - Apache - 流式传输 HTML5 视频,无需为每个视频制作网页