In a JSF application running on Tomcat: 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
:
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
:
@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
:
<?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
:
<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>
Information regarding the environment:
- Maven
- Tomcat 8 via Eclipse Neon
- CDI:
weld-servlet-core
(2.4.1.Final; emptybean.xml
in folderWEB-INF
) - Bean Validation:
hibernate-validator
(5.3.3.Final) - JSF:
com.sun.faces
(2.2.14)
Many thanks for any help.