【发布时间】:2023-03-08 21:57:01
【问题描述】:
我想将“HELLO|WORLD”值移动到 YML 文件中。然后在正则表达式中调用 YML 文件中的值。
例如, 以下是 YAML 文件 YML文件
valid-caller-value: HELLO|WORLD
获取 YAML 值的 Java 类
@Configuration
@ConfigurationProperties
@Data
@NoArgsConstructor
public class Properties {
private String validCallerValue;
}
使用正则表达式验证的 Java 类
@Data
@AllArgsConstructor
@NoArgsConstructor
@SearchCriteriaValidator
public class classOne {
@Pattern(regexp = ""HELLO|WORLD", flags = Pattern.Flag.CASE_INSENSITIVE, message = "callerValue key has invalid value. No leading or trailing space(s) are allowed")
protected String callerValue;
}
我想做类似的事情,而不是字符串。
@Pattern(regexp = properties.getValidCallerValue())
我已经尝试过以下注释。他们都没有工作
@Pattern(regexp = "#\\{@properties.getValidCallerValue()}")
@Pattern(regexp = "$\\{properties.getValidCallerValue()}
有可能实现吗?
注意:我真的不想使用常量。
【问题讨论】:
标签: java regex spring hibernate yaml