LINUX.ORG.RU

[spring][aop][oval] небольшая проблема

 


0

0

Доброго времени суток.

Использую oval (spring+oval) для проверки входных данных.

Есть класс Account вроде этого:

@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; 

} 

} 

И конфигурация:

 

<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> 

AccountUpdateController выглядит примерно так:

 

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); 

} 

... 

} 

И работает это всё просто великолепно. Я получаю исключение если пользователь присылает неверное мыло.

Но аккаунт должен быть request-scoped по задумке.

Меняю конфигурацию на такую

 

<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> 

И ловлю в логах сообщения типа:

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

Я вроде понимаю, что код не может создать подкласс класса $Proxy25 (который, видимо, в свою очередь есть подкласс Account). Но толку от того, что я понимаю.. как починить?

Есть другой способ - просто использовать валидатор овала и вызывать метод validate ручками.

Но всё же предпочтительней было бы испльзовать первый способ (с aop), если получится.

Как бы сконфигурять это?

★★★★★

Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.