【问题标题】:Disable replacement of XML eXternal entities in Spring Jaxb2RootElementHttpMessageConverter在 Spring Jaxb2RootElementHttpMessageConverter 中禁用 XML eXternal 实体的替换
【发布时间】:2015-05-11 15:15:40
【问题描述】:

我有一个基于注释的 Spring Web 应用程序控制器,它将 XML 映射到带注释的普通旧 java 对象。示例代码如下:

@Controller
@RequestMapping("/")
public class Endpoint {

    @RequestMapping
    public void send(...) {
        ...
    } 
    ...

映射是通过 Jaxb2RootElementHttpMessageConverter 自动完成的,目前可以引用和替换接收到的 XML 中的内容。

我的问题是,是否有可能——例如通过 beans.xml——配置 Jaxb2RootElementHttpMessageConverter 以防止替换实体?

转换器由 Spring 自动创建。

【问题讨论】:

    标签: java spring spring-mvc jaxb2


    【解决方案1】:

    如果你想覆盖一个由 spring 创建的 bean,你只需定义你自己的相同类型的 bean。此外,您可以将其标记为@Primary。我没有用 Jaxb2RootElementHttpMessageConverter 尝试过,但它可以与 ObjectMapper 一起使用,如下所述:

    http://docs.spring.io/spring-boot/docs/current/reference/html/howto-spring-mvc.html#howto-customize-the-jackson-objectmapper

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-01
      • 2011-09-01
      • 1970-01-01
      相关资源
      最近更新 更多