2015-10-05 84 views
1

在項目的jar中有一個validation.xml包含了Address bean的字段級驗證。javax.validation.ValidationException:已經在xml中配置了%class%

另一個項目使用Address類並需要進行特定的地址驗證。因此,使用Address bean的類級驗證創建了extended-validation.xml。

因此,在應用程序部署期間,ValidationException發生:javax.validation.ValidationException: my.base.datatypes.Address has already be configured in xml.

這裏是兩個帶有基本驗證和「擴展驗證」的驗證xml文件。

的validation.xml

<bean class="my.base.datatypes.Address" ignore-annotations="true"> 
    <getter name="country"> 
     <constraint annotation="my.imp.services.validation.ValidCode"> 
      <message>{msg01}</message> 
      <groups> 
       <value>my.imp.services.validation.ImportGroup</value> 
      </groups> 
      <element name="name">Country</element> 
     </constraint> 
    </getter> 
</bean> 

擴展的validation.xml

<bean class="my.base.datatypes.Address" ignore-annotations="true"> 
    <class ignore-annotations="true"> 
     <constraint annotation="my.extended.imp.services.validation.ValidAddress"> 
      <message>ERROR DURING ADDRESS VALIDATION</message> 
      <groups> 
       <value>my.imp.services.validation.ImportGroup</value> 
      </groups> 
     </constraint> 
    </class> 
</bean> 

是否有可能擴大現有的驗證?

回答

0

該解決方案看起來非常簡單和微不足道。如果要擴展驗證規則,請使用不同的驗證程序,它將加載約束配置extended-validation.xml。在這種情況下,基礎驗證器根據validation.xml config驗證數據,另一驗證器根據extended-validation.xml config驗證數據。所以不會再發生配置衝突。

相關問題