Spring provide a nice feature that allow programmer to define annotations in java source code to setup @Value("systemProp:defaultvalue") and other injected dependency.
However, in some case we may forget to enable the <context:annotation-config/> in a mixed XML and annotation spring program.
Is there a way, an utility method or a pattern to put in the java class to enforce the <context:annotation-config/> is not being forgotten?
Write a test case that fails if
<context:anotation-config/>is not configured right.If you really want to check if in production, then define a default value and inject this default value.
Then you need to check it in the constructor for example.public class Demo() {
Does not work because the Value is injected after the constructor is invoked.
If @Autowired is supported the you can have it all in an seperate method:
If your problem is not that you need to enable
anntation-configfor each class then it would be enougth to have one bean that implements this check logic. If not, and do not want to put this lines in every class, then you can do it with AspectJ intertype declartions.