0

We are currently converting from Wildfly to SpringBoot + Resteasy, and the last hurdle we have hit is validation that requires dependency injection.

The solution is using

  • Spring boot 2.2.5.RELEASE
  • resteasy-spring-boot-starter 3.3.1.Final
  • resteasy-validator-provider-11 3.6.3.SP1

One of the validators with the issue has the following form

@Component
public class FieldsValidValidator implements ConstraintValidator<FieldsValidValid, RequestDTO> {
    @Inject
    private CancellationFieldController cancellationFieldController;

    @Override
    public boolean isValid(RequestDTO requestDTO, ConstraintValidatorContext context) {
        var stuff = controller.getStuff(requestDTO.getStuffId()); // controller is null here

On Wildfly with weld and a @Stateless annotation the validator gets the controller injected, but I cannot figure out how to get it injected in Spring Boot, its like the hibernate-validator stuff is unaware of Spring Boots context.

Torben Pi Jensen
  • 850
  • 9
  • 27
  • Did you find a solution ? – SeleM Jul 29 '20 at 16:16
  • 1
    Unfortunately no - we ended up adding a @Configuration class that has the CancellationFieldController as dependency and then set a static public field on the validator. It works, but I would not add it as an solution to this question. – Torben Pi Jensen Aug 05 '20 at 09:26

0 Answers0