I have a Spring 4 app with hibernate-validator on the classpath. I have a bean class which uses some javax validation annotations for the bean properties and I have another class that accepts that bean in it's constructor.
Java:
public class Config {
@NotNull
@Size(min=10)
public final String test;
@Min(5)
public final int num;
public Config(String test, int num) {
this.test = test;
this.num = num;
}
//getters
}
public class Test {
private Config config;
public Test(@Valid Config config) {
this.config = config;
}
}
My Spring application context is as follows:
<bean id="config" class="com.Config">
<constructor-arg type="java.lang.String">
<value>aaaa</value>
</constructor-arg>
<constructor-arg type="int">
<value>2</value>
</constructor-arg>
</bean>
<bean id="test" class="com.Test">
<constructor-arg ref="config" />
</bean>
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
Note that the validator is defined in the application context. When I run the app as is, I expect an exception to be thrown when the bean is set into the test class constructor because the two arguments do not meet the constraints, but it runs without any exception. Am I missing something else?