I have the following structure ina project I am using to learn JavaEE7:
Bean:
@Stateless
public class MyBean implements MyInterface{
public String lookup(@NotNull String text){
return "found3";
}
}
Interface:
public interface MyInterface {
public String lookup(@NotNull String text);
}
and a second bean:
public class HelloWorld {
@Inject
private MyInterface bean;
public String getMessage() {
return bean.lookup(null);
}
}
My server is a WildFly 8.2.
I would like to have the lookup method validated when calling it, so I annotated the parameter so it doesn't accept null.
The problem is that this code runs OK when I call the HelloWorld.getMessages() (I get the return value "found3".
If I copy the validation form MyInterface to MyBean, I get the validaiton exception as I wanted.
Is it possible to declare the validation in the interface? How do I do that?