Hello,
pls, sorry my english.
I'm using oval (spring+oval) for input data validation.
I have Account class like this:
And configuration like this:Code:@Guarded public class Account implements Serializable { @NotNull(message="email must not be null") @Email(message="email is invalid") private String email; public void setEmail(@AssertFieldConstraints("email") String email) { this.email = email; } public String getEmail() { return email; } }
My AccountUpdateController looks like this:Code:<bean id="account" factory-bean="accountDao" factory-method="getAccount"> <constructor-arg value="1" /> </bean> <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="account" /> <property name="interceptorNames"><list><value>ovalGuardInterceptor</value></list></property> </bean>
And that works perfectly. I have exception when user sends wrong email.Code:public class AccountUpdateController extends AbstractController { private AccountDao accountDao; private Account account; public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) { Map<String, Object> model = new HashMap<String, Object>(); try { account.setEmail(request.getParameter("email")); accountDao.updateAccount(account); model.put("message", "account updated"); } catch(ConstraintsViolatedException e) { model.put("message", "error: " + e.getMessage()); } return new ModelAndView("async/json", "model", model); } ... }
But, account is request-scoped.
I'm changing my servlet-config to something like this
And have messages in log like this:Code:<bean id="account" factory-bean="accountDao" factory-method="getAccount" scope="request"> <constructor-arg value="1" /> <aop:scoped-proxy /> </bean> <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="*account*" /> <property name="interceptorNames"><list><value>ovalGuardInterceptor</value></list></property> </bean>
I think i understand that code cannot subclass final class class $Proxy25 (which is subclass of Account i suppose). But how to fix it?Code:Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class $Proxy25]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy25
Another way - just use oval validator and validate object manully after set values.
But if possible, i'll prefer first way (with aop).
Could anybody please advise me, how to configure it?


Reply With Quote

