如何在Spring 3中强制禁用JSR-303支持?
问题内容:
我在同一工件(使用maven构建)中混合了一些旧的Spring
MVC代码和gwt代码,但我无法使其运行。它需要运行时不需要的验证提供程序(因为我没有使用任何JSR-303验证批注),并且不需要CP(它可能与将部署此工件的某些应用程序容器冲突)
如何强制spring不执行任何JSR-303验证并摆脱对验证提供程序的运行时依赖性?
由于GWT以某种方式使用了PS工件,因此它在CP中具有validate-api
PPS似乎可以<mvc:annotation- driven/>
从Spring配置中删除来解决此问题。绑定和经典验证仍然有效(我已<context:annotation-config/>
启用)
问题答案:
您已经发现,<mvc:annotation-driven/>
设置了许多功能,包括JSR-303。等效为
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="order" value="0" />
</bean>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
<property name="validator" ref="validator" />
</bean>
</property>
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
<bean class="org.springframework.http.converter.StringHttpMessageConverter" />
<bean class="org.springframework.http.converter.FormHttpMessageConverter" />
<bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter" />
</list>
</property>
</bean>
<bean id="validator"
class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
<bean id="conversion-service"
class="org.springframework.format.support.FormattingConversionServiceFactoryBean" />
因此,您可以将标签替换到该xml配置中,并删除不需要的部分。