2014-11-22 6 views
0

타원형 검증 Fwk + Spring을 사용하고 있습니다. 어노테이션을 사용하여 비즈니스 로직 메소드의 유효성을 검사하려고합니다. 타원형 페이지에서 멋진 예제를 발견했습니다. http://best-practice-software-engineering.ifs.tuwien.ac.at/repository/net/sf/oval/oval/1.61/tmp/docs/userguide.html#d4e489타원형 맞춤법 검사 - 사전 조건

사용자 지정 유효성 검사를 만들기위한 것입니다. 그러나 제공된 예제는 이전에 메소드가 실행 된 후에 작동하는 것 같습니다. 예제와 동일하게 구현할 수 있습니까?

여기 내 스프링 구성입니다.

<bean id="ovalGuardInterceptor" class="net.sf.oval.guard.GuardInterceptor" /> 

<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> 
    <property name="proxyTargetClass" value="true" /> 
    <property name="beanNames" value="productGetBusinessLogic" /> 
    <property name="interceptorNames"><list><value>ovalGuardInterceptor</value></list></property> 
</bean> 

이이 내 주석 클래스

@Retention(RetentionPolicy.RUNTIME) 
@Target({ElementType.METHOD}) 
@Documented 
@net.sf.oval.configuration.annotation.Constraint(checkWith = TestValidatorCheck.class) 
public @interface TestValidator { 
/** 
* Message to be used for the ConstraintsViolatedException 
* 
* @see ConstraintsViolatedException 
*/ 
String message() default "must be upper case"; 
} 

내 체크 클래스

import net.sf.oval.Validator; 
import net.sf.oval.configuration.annotation.AbstractAnnotationCheck; 
import net.sf.oval.context.OValContext; 

public class TestValidatorCheck extends AbstractAnnotationCheck<TestValidator> { 
    public boolean isSatisfied(Object validatedObject, Object valueToValidate, OValContext context, Validator validator) { 
    if (valueToValidate == null) 
     return true; 
    String val = valueToValidate.toString(); 
    return val.equals(val.toUpperCase()); 
    } 
} 

이며,이 방법은 알려주세요

@Override 
@TestValidator 
public ProductGetResponse getProductBulk(ProductGetKey productGetKey) throws ItemWrapperApiException { 

을 주석 방법이 무엇인지 나는 여기에서 놓치고있다. 감사.

답변

0

제약 조건 주석을 추가 한 방법에 따라 반환 값에 대한 제약 조건으로 선언됩니다.

@Override 
public ProductGetResponse getProductBulk(@TestValidator ProductGetKey productGetKey) throws ItemWrapperApiException 
이 검증 될 방법 매개 변수에 직접 주석을 지정할 필요가 인수 검증, 즉 : 들어