非常极端的情况,谷歌搜索似乎没有帮助。
我必须使用 xml 验证(生成的代码),场景类似于:
// This file was generated by the JavaTM Architecture for XML
Binding(JAXB) Reference Implementation, v2.2.4
...
@XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "xxx", propOrder
= { ... }) @XmlRootElement(name = "xxx") public class Class01DTO
implements Serializable { ...
@XmlElement(required = true)
protected BetslipDTO.SlipPlacement slipPlacement;
...
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = { ...
})
public static class Class02
implements Serializable
{
private final static long serialVersionUID = ...;
protected String stringToValidate;
}
}
我对如何验证“stringToValidate”没有信心。我有一个约束映射.xml,例如:
<bean class="com.etc.Class01DTO.Class02">
<field name="stringToValidate">
<constraint annotation="javax.validation.constraints.NotNull">
</constraint>
</field>
</bean>
那只会产生错误。尝试了不同的组合,但没有结果。有没有人遇到过同样的情况?我认为很明显代码已生成,因此不能使用基于注释的验证选项...
进行构建时的错误类似于以下内容...
shouldValidateSpringContext(com.etc.TestBetSpringContext): Error creating bean with name 'validatorFactoryBean' defined in class path resource [spring/bet-service.xml]: Invocation of init method failed; nested exception is javax.validation.ValidationException: HV000065: Unable to load class: com.etc.Class01DTO.Class02.