I had a situation before where i wanted to use Spring's Validator interface around my business services. The scenario was i wanted to automatically call the validate method when a service method is invoked.
i am not using Spring MVC, which allows validation at binding level. Anyway, i had to do a workaround & using AOP i tried to proxy each business service & inject the validator on certain method patterns, as shown
The ValidatorProxyFactoryBean actually is responsible for creating the actual proxy. Developer creates the validator i.e. AliasValidator & only is concerned with validations related to the current scenario.
<bean id="aliasValidatorDao" class="validation.core.factory.ValidatorProxyFactoryBean">
<property name="oracleProcedureSupport"> <ref bean="oracleProcSupport" /></property>
<bean class="xxx.xxxx.xxxxx.xxx.AliasValidator" />
<!--setting this to false will disable the validation -->
Furthermore, StrutsMessagesSupport implements the Errors interface & uses internally ActionMessages.
Anyway, i hope this approach was worth the effort. If you do like what you see or if you think there is a better way of configuring this [maybe through AspectJ], please let me know. Most of us don't have luxury of using Spring MVC, moreover i rather have all validations done on the service side [complex ones]