【问题标题】:Spring configuration unable to expand propertySpring配置无法扩展属性
【发布时间】:2014-12-09 17:30:02
【问题描述】:

我正在尝试通过属性文件启用或禁用授权。但是以下不起作用

<global-method-security pre-post-annotations="${enabled}" />

xml 验证失败

在这一行找到多个注释: - cvc-enumeration-valid:值 '${enabled}' 对于枚举 '[disabled, enabled]' 不是 facet-valid。它必须是来自 枚举。

有人可以建议我这样做的正确方法吗?

【问题讨论】:

  • 你定义了一个 context:property-placeholder bean 吗?
  • @DonBottstein 是的,我在 Eclipse 上这样做了,但 xml 验证失败了。引起:org.xml.sax.SAXParseException;行号:9;列号:130; cvc-enumeration-valid:值 '${enabled:enabled}' 对于枚举 '[disabled, enabled]' 不是 facet-valid。它必须是来自枚举的值。

标签: java spring


【解决方案1】:

不幸的是,Spring Security XSD 硬编码了 IIRC(和其他)属性的可能值:

<xs:attributeGroup name="global-method-security.attlist">
  <xs:attribute name="pre-post-annotations">
    <xs:annotation>
      <xs:documentation>Specifies whether the use of Spring Security's pre and post invocation annotations
        (@PreFilter, @PreAuthorize, @PostFilter, @PostAuthorize) should be enabled for this
        application context. Defaults to "disabled".
      </xs:documentation>
    </xs:annotation>
    <xs:simpleType>
      <xs:restriction base="xs:token">
        <xs:enumeration value="disabled"/>
        <xs:enumeration value="enabled"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:attribute>
...

因此,如果您希望 XML 验证成功,则无法进行属性替换(因为 XML 验证不知道 Spring 的替换标记)。

【讨论】:

  • 所以也许 Spring profiles 是一个选择。
  • @don-bottstein 感谢 Spring 配置文件的链接;在过去的几年里,我并没有在 Spring 上工作太多。马扬克-古普塔
  • @mayank-gupta,你应该试一试个人资料,只要你没有太多不同的属性组合需要支持,它看起来就可以满足要求。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-12-13
  • 2020-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-03
  • 1970-01-01
相关资源
最近更新 更多