有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Spring配置无法扩展属性

我正试图通过属性文件启用或禁用授权。但下面的方法行不通

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

xml验证失败

在此行找到多个批注: -cvc枚举有效:值“${enabled}”对于枚举“[disabled,enabled]”无效。它必须是来自 枚举

有人能给我建议正确的方法吗


共 (1) 个答案

  1. # 1 楼答案

    不幸的是,Spring Security XSDs硬编码了该(和其他)属性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的替换标记)