例外を処理するために、Spring MVC 3.2 の ExceptionHandler で注釈が付けられたメソッド内でカスタム引数を使用しようとしています。ただし、メソッドが実行されると、まだこの例外が発生します。
コントローラ メソッドは次のようになります。
@ExceptionHandler(IOException.class)
@ResponseBody
public Error handleIOException(IOException ex, CustomArgument customArgument) {
return new Error(customArgument.getMessage());
}
そして、私は次のxml構成を使用しています:
<mvc:annotation-driven>
<mvc:argument-resolvers>
<bean class="com.example.spring.CustomArgumentWebArgumentResolver" scope="singleton">
<constructor-arg ref="customArgumentService" />
</bean>
</mvc:argument-resolvers>
</mvc:annotation-driven>
<bean id="customArgumentService" class="com.example.service.CustomArgumentService" scope="singleton" />
<bean class="org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver" scope="singleton">
<property name="customArgumentResolvers">
<list>
<bean class="com.example.service.CustomArgumentService" scope="singleton">
<constructor-arg ref="customArgumentService" />
</bean>
</list>
</property>
</bean>
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" scope="singleton">
<property name="defaultErrorView" value="forward:/error" />
</bean>
そして、mvc:annotation-driven は既に ExceptionHandlerExceptionResolver を割り当てていると思うので、どうすればそれに customArgumentResolver を追加できますか。どんな助けでも大歓迎です。