In a JSF application (using Hibernate Validator and the reference implementation of CDI Weld) running on Tomcat 8: Using @Inject in a ConstraintValidator results in a javax.validation.ValidationException: HV000028: Unexpected exception during isValid call.Elsewhere in the application, CDI works without errors.
The ConstraintValidator looks like:Code:
public class MyIntervalValidator implements ConstraintValidator<MyInterval, Integer> {
@Inject
private Interval interval;
public void initialize(MyInterval myIntervall) {
}
public boolean isValid(Integer i, ConstraintValidatorContext ctx) {
Integer ceiling;
ceiling = interval.getCeiling();
if ((0 <= i) && (i <= ceiling)) {
return true;
}
return false;
}
I checked the injection:
interval is
null during the execution of the method
isValid.
The Interval: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;
}
}
The context.xml:Code:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="BeanManager"
auth="Container"
type="javax.enterprise.inject.spi.BeanManager"
factory="org.jboss.weld.resources.ManagerObjectFactory" />
</Context>
Detail from the web.xml:Code:
<resource-env-ref>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>
javax.enterprise.inject.spi.BeanManager
</resource-env-ref-type>
</resource-env-ref>
The dependencies:Code:
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.14</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.14</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.3.4.Final</version>
</dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator-cdi</artifactId>
<version>5.3.4.Final</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.el</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet-core</artifactId>
<version>2.4.1.Final</version>
</dependency>
Information regarding the environment:- Maven
- Tomcat 8 via Eclipse Neon
- CDI: weld-servlet-core (empty bean.xml in folder WEB-INF)
- Bean Validation: hibernate-validator
- JSF: com.sun.faces
Many thanks for any help.