JSR-303验证对我不起作用。我使用的是Jersey的以下版本
<jersey.version>1.2</jersey.version>
<jaxrs.version>1.1.1</jaxrs.version>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.0.2.GA</version>
<scope>runtime</scope>
</dependency>
public class Employee{
@JsonProperty("name")
@NotNull
private String name;
}
@POST
@Consumes("application/json")
@Produces({"application/json"})
public void postTradeParties(@Valid Employee entity){
}
如果名称为空,则不应该发生Post.It应该给出400错误。 验证似乎不起作用.Below是web.xml中的条目
<servlet>
<servlet-name>ResourceConfig</servlet-name>
<servlet- class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<!-- <param-name>com.sun.jersey.config.property.packages</param-name> -->
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.hsbc.net.dc.web.config.MyResourceConfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ResourceConfig</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>