Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force disable JSR-303 support in Spring 3?

I have some legacy Spring MVC code mixed with gwt code in same artifact (built using maven) and I cannot make it run. It wants validation provider at runtime which i do not need (since I'm not using any JSR-303 validation annotations) and do not want in CP (it may conflict with some app containers this artifact will be deployed in)

How to force spring not to do any JSR-303 validations and get rid of runtime dependency on validation provider?

PS artifact has validation-api in CP since GWT is using it somehow

PPS Seems like removing <mvc:annotation-driven/> from Spring config fixes this. Binding and classic validations still works (I have <context:annotation-config/> enabled)

like image 754
float_dublin Avatar asked Dec 08 '11 03:12

float_dublin


1 Answers

As you already discovered, <mvc:annotation-driven/> sets a lot of features including JSR-303. The equivalent is

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

So you may substitute the tag onto this xml configuration and remove parts you don't need.

like image 55
Alexey Grigorev Avatar answered Oct 18 '22 10:10

Alexey Grigorev