我有一個控制器的方法來實例化一個日曆:如何防止在@ModelAttribute方法
public FormValidationResult submitFormAndSendEmail(@Valid ContactForm form, BindingResult result,
@HttpSessionParam(value = "lastTimeContactFormSent", required = false) Calendar lastTimeContactFormSent)
正如你可以看到我已經創建了一個@HttpSessionParam註釋,這將需要一個變量從HttpSession中並將其放入指定的方法參數中。
但是......
的說法正在被解決之前,我收到一封InstantiationExceptionConstructorAccessorImpl因爲日曆無法通過默認的構造函數來實例化。
使用給定的堆棧跟蹤,我看到「resolveModelAttribute」中的HandlerMethodInvoker導致實例化。
我該如何預防?我不想實例化,我想使用我自己的WebArgumentResolver來填充方法參數。
任何線索?
更多信息: 堆棧跟蹤由Spring(3.0.4):
java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:30)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveModelAttribute(HandlerMethodInvoker.java:772)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:356)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:427)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:415)
我沒有看到調試器擊中webargumentresolver。
的論點是在我的應用程序上下文(XML)的定義如下:
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="customArgumentResolver" ref="sessionParamResolver"/>
</bean>
<!-- annotation to resolve httpSession attributes -->
<bean id="sessionParamResolver" class="nl.usgpeople.vakgilde.spring.mvc.extensions.SessionParamArgumentResolver"/>
順便說一句,通過這樣做,你將覆蓋默認的AnnotationMethodHandlerAdapter。這是春天的一個錯誤,請看這裏:http://forum.springsource.org/showthread.php?p = 272494,您需要取出mvc:annotation-driven標籤以獲得完全控制權。 – 2011-02-11 12:05:07