[jboss-jira] [JBoss JIRA] (WFLY-3088) Cannot Inject Validator using @Inject

Eduardo Martins (JIRA) issues at jboss.org
Sat Mar 8 09:30:33 EST 2014


    [ https://issues.jboss.org/browse/WFLY-3088?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12951330#comment-12951330 ] 

Eduardo Martins commented on WFLY-3088:
---------------------------------------

Please attach the server.log.

Also, it would be great if you could attach the deployments that would allow us to replicate the issue.
                
> Cannot Inject Validator using @Inject
> -------------------------------------
>
>                 Key: WFLY-3088
>                 URL: https://issues.jboss.org/browse/WFLY-3088
>             Project: WildFly
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>          Components: CDI / Weld
>    Affects Versions: 8.0.0.Final
>            Reporter: Sat B
>            Assignee: Eduardo Martins
>
> I have a very simple bean and I am trying to inject the Validator using the @Inject annotation. But I am ending up getting a null when I try to use the Validator. I have the beans.xml defined to bean-discovery-mode="all". Below is the code
> --------
> import javax.inject.Inject;
> import javax.validation.ConstraintViolation;
> import javax.validation.Validation;
> import javax.validation.Validator;
> import javax.validation.ValidatorFactory;
> import javax.validation.constraints.*;
> import java.util.Map;
> import java.util.Set;
> public class SimpleCommand {
>     @Inject
>     private Validator validator;
>    
>     @Email
>     private String email;
>     
>     public SimpleCommand(){
>     }
>     public SimpleCommand(Map<String, String[]> params){
>         this.email = params.get("email")!=null ? params.get("email")[0] : null;
>     }
>     public void validate(){
>         //USING VALIDATOR THAT IS INJECTED IS NULL HERE
>         //USING THE BELOW METHOD WORKS
>         ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
>         Validator validator1 = factory.getValidator();
>         Set<ConstraintViolation<SimpleCommand>> contstraintViolations = validator1.validate(this); //USING INJECTED VALIDATOR WILL THROW NULL POINTER EXCEPTION
>         for (ConstraintViolation<SimpleCommand> violation : contstraintViolations){
>             System.out.println(violation.getMessage());
>         }
>     }
> }
> --------
> Then, from a JAX-RS controller, I call this validator
> ------
> SimpleCommand cmd = new SimpleCommand(req.getParameterMap());
>         cmd.validate();
> -----

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the jboss-jira mailing list