javaspring-bootoval

Problems with validation on Spring Boot and OVal


Good day. I have app on Spring Boot 1.3 with net.sf.oval 1.85. My model:

@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;

}

My controller:

@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);
    }
}

But @Valid did not work. How to connect spring boot and oval correctly? In project I use only annotation without XML. Any body have some ideas?


Solution

  • You can use the 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. As value for the beanNames attribute you would use "*Controller" to match all Spring MVC Controller classes.