title: Bean Validation (ConstraintValidator) + CDI + Tomcat 8: HV000028: Unexpected exception during isValid call
body: <p>In a JSF application running on Tomcat: Using <code>@Inject</code> in a <code>ConstraintValidator</code> results in a <code>javax.validation.ValidationException</code>: <em>HV000028: Unexpected exception during isValid call.</em></p>
  
  <p>Elsewhere in the application, CDI works without errors.</p>
  
  <p>The <code>ConstraintValidator</code>:</p>
  
  <pre><code>public class MyIntervalValidator implements ConstraintValidator&lt;MyInterval, Integer&gt; {
  
      @Inject
      private Interval interval;
  
      public void initialize(MyInterval myIntervall) {
      }
  
      public boolean isValid(Integer i, ConstraintValidatorContext ctx) {
  
          Integer ceiling;
  
          ceiling = interval.getCeiling();
  
          if ((0 &lt;= i) &amp;&amp; (i &lt;= ceiling)) {
              return true;
          }
  
          return false;
      }
  </code></pre>
  
  <p>I checked the injection: <code>interval</code> is <code>null</code> during the execution of the method <code>isValid</code>.</p>
  
  <p>The <code>Interval</code>:</p>
  
  <pre><code>@SessionScoped
  public class Interval implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      @Min(value = 1)
      private Integer ceiling;
  
      public Interval() {
          this.ceiling = 1;
      }
  
      public Integer getCeiling() {
          return ceiling;
      }
  
      public void setCeiling(Integer ceiling) {
          this.ceiling = ceiling;
      }
  
  }
  </code></pre>
  
  <p>The <code>context.xml</code>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;Context&gt;
      &lt;Resource name="BeanManager" 
          auth="Container"
          type="javax.enterprise.inject.spi.BeanManager"
          factory="org.jboss.weld.resources.ManagerObjectFactory" /&gt;
  &lt;/Context&gt;
  </code></pre>
  
  <p>Detail from the <code>web.xml</code>:</p>
  
  <pre><code>&lt;resource-env-ref&gt;
     &lt;resource-env-ref-name&gt;BeanManager&lt;/resource-env-ref-name&gt;
     &lt;resource-env-ref-type&gt;
        javax.enterprise.inject.spi.BeanManager
     &lt;/resource-env-ref-type&gt;
  &lt;/resource-env-ref&gt;
  </code></pre>
  
  <p><strong>Information regarding the environment:</strong></p>
  
  <ul>
  <li>Maven</li>
  <li>Tomcat 8 via Eclipse Neon</li>
  <li>CDI: <code>weld-servlet-core</code> (2.4.1.Final; empty <code>bean.xml</code> in folder <code>WEB-INF</code>)</li>
  <li>Bean Validation: <code>hibernate-validator</code> (5.3.3.Final)</li>
  <li>JSF: <code>com.sun.faces</code> (2.2.14)</li>
  </ul>
  
  <p>Many thanks for any help.</p>