0

I'm trying to use Oval 1.84 for getting around some validation constraints without boilerplates. The validation works when I mark fields with @NotNull (javax.validation.constraint and net.sf.oval.validator).

But doesn't work in the case of implementing constarints to method and constructor parameters.

Somasundaram Sekar
  • 5,244
  • 6
  • 43
  • 85
  • I know it's an old question, but I think the answer I posted here: http://stackoverflow.com/questions/43859895/hibernate-validator-method-or-constructor-validation/43991633#43991633 may help if someone else comes across this post. – Kai May 16 '17 at 05:18

1 Answers1

0

Parameter validation requires the use of some method invocation intercepting bytecode. OVal provides ready to use implementations for AspectJ and Spring AOP.

With AspectJ

How to use it with AspectJ is documented in detail at http://oval.sourceforge.net/userguide.html#programming-by-contract

With Spring AOP

The usage with Spring AOP is outlined in the test case at https://svn.code.sf.net/p/oval/code/trunk/src/test/java/net/sf/oval/test/integration/spring/SpringAOPAllianceTest.java

In Spring you need to configure your beans for which you want to have method parameter validation, e.g.:

<bean id="myService" class="com.example.MyService" />

And an Invocation Interceptor:

<bean id="ovalGuardInterceptor" class="net.sf.oval.guard.GuardInterceptor" />
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
    <property name="proxyTargetClass" value="false" />
    <property name="interceptorNames">
        <list>
            <value>ovalGuardInterceptor</value>
        </list>
    </property>
    <!-- the next line tells which beans you want to use validation for -->
    <property name="beanNames" value="myService" />
</bean>
Seb T
  • 795
  • 8
  • 16