I am working on the JSR validations using spring (4.2.0.RELEASE), hibernate validator (5.2.1.Final) and validation api (1.1.0.Final) for the backend appliation with the below configurations,
<bean id="validatorFactory" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<property name="validationMessageSource" ref="messageSource" />
</bean>
<bean class="org.springframework.expression.spel.standard.SpelExpressionParser" />
but None of the JSR 303 annotations are working in my application.
Note: Added jsr 303 annotations on POJO class and @Validated on the service class (Which is using the POJO) also tried adding @Validated on the method level.
Update: Service Interface
@Validated
public interface SampleService {
@NotNull
@Valid
Account getAccount( @NotNull @Valid String customerKey, @NotNull String name);
Service Implementation
@Service
@Validated
@Transactional( readOnly=true )
public class SampleServiceImpl
implements SampleService
{
private final SampleDao sampleDao;
@Inject
public SampleServiceImpl( SampleDao sampleDao)
{
this.sampleDao= sampleDao;
}
@Override
@Validated
public Customer getAccount( String customerKey, String name)
{
try {
return sampleDao.getAccount( customerKey, name);
}
catch ( EmptyResultDataAccessException e ) {
throw new NotFoundException( e );
}
}