gpt4 book ai didi

java - 如何在 Spring 3 中强制禁用 JSR-303 支持?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:20:57 26 4
gpt4 key购买 nike

我在同一个工件(使用 Maven 构建)中有一些遗留的 Spring MVC 代码和 gwt 代码混合在一起,我无法让它运行。它需要运行时的验证提供程序,而我不需要(因为我没有使用任何 JSR-303 验证注释)并且不希望在 CP 中使用(它可能与将部署此工件的某些应用程序容器冲突)

如何强制 spring 不执行任何 JSR-303 验证并摆脱对验证提供程序的运行时依赖?

PS 工件在 CP 中有验证 api,因为 GWT 正在以某种方式使用它

公务员事务局似乎要删除 <mvc:annotation-driven/>来自 Spring 配置修复了这个问题。绑定(bind)和经典验证仍然有效(我启用了 <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 配置中并删除不需要的部分。

关于java - 如何在 Spring 3 中强制禁用 JSR-303 支持?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8425788/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com