javax.validation.ValidationException:RESTful webservice

时间:2017-07-07 11:48:22

标签: web-services rest validation cxf bean-validation

我正在尝试为我的REST API实现JSON POST请求的输入验证。我正在使用Bean Validation API和@NotNull注释。当我删除验证配置时,我的API工作正常但是使用Bean Validation API会抛出 javax.validation.ValidationException:Service Object为null 异常。 我的配置是

<jaxrs:server id="accrualService" address="/accrualService">
    <jaxrs:serviceBeans>
        <ref bean="accrualWebService" />
    </jaxrs:serviceBeans>   
     <jaxrs:extensionMappings>
        <entry key="json" value="application/json"/>
    </jaxrs:extensionMappings>
    <jaxrs:features>
        <ref bean="commonValidationFeature" />
    </jaxrs:features>
    <jaxrs:providers>
        <bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
        <!--To generate Error response in case of exception -->
        <bean class="com.webservice.exceptions.AccrualServiceExceptionMapper" />
    </jaxrs:providers>
</jaxrs:server>

<bean id="commonValidationFeature" class="org.apache.cxf.validation.BeanValidationFeature" />
<bean id="accrualWebService" class="com.webservices.impl.AccrualWebServiceImpl" scope="prototype">
    <property name="accrualWebServiceManager" ref="accrualWebServiceManager"/>
</bean>

我的cxf版本是2.5.2,cxf-rt-core版本是2.5.2。 我使用了@NotNull注释,这对我不起作用。我是否遗漏了一些配置,如何仅使用注释成功实现输入验证?

0 个答案:

没有答案