以下の構成で、バックエンド アプリケーションのスプリング (4.2.0.RELEASE)、休止状態バリデーター (5.2.1.Final)、および検証 API (1.1.0.Final) を使用して、JSR 検証に取り組んでいます。
<bean id="validatorFactory" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<property name="validationMessageSource" ref="messageSource" />
</bean>
<bean class="org.springframework.expression.spel.standard.SpelExpressionParser" />
しかし、私のアプリケーションでは JSR 303 アノテーションが機能していません。
注: POJO クラスに jsr 303 アノテーションを追加し、サービス クラス (POJO を使用している) に @Validated を追加し、メソッド レベルで @Validated を追加しようとしました。
更新:サービスインターフェース
@Validated
public interface SampleService {
@NotNull
@Valid
Account getAccount( @NotNull @Valid String customerKey, @NotNull String name);
サービスの実装
@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 );
}
}