Spring Boot 和 OVal 的验证问题

Problems with validation on Spring Boot and OVal

美好的一天。我在 Spring Boot 1.3 和 net.sf.oval 1.85 上安装了应用程序。 我的模型:

@Entity
@Table(name = "company")
public class Company extends BaseModel {

    @NotBlank
    @NotNull
    @Length(min = 5, max = 50)
    @Column(nullable = false, name = "name", length = 50)
    private String name;

}

我的控制器:

@RestController
@RequestMapping("/company")
public class CompanyController {

    @Autowired
    private CompanyService companyService;

    @RequestMapping(value = "", method = RequestMethod.POST)
    public Company saveCompany(@RequestBody(required = true) @Valid Company company) {
        return companyService.save(company);
    }
}

但是@Valid 没有起作用。如何正确连接spring boot 和 oval? 在项目中,我只使用没有 XML 的注释。 任何人有一些想法吗?

您可以使用org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator for that. It should be sufficient to instantiate the beans (GuardInterceptor, BeanNameAutoProxyCreator) programmatically in your Spring configuration class, that are configured via XML in the example at 8.4.2. Guarding Spring managed beans using Spring AOP。作为 beanNames 属性的值,您将使用“*Controller”来匹配所有 Spring MVC Controller 类.