Using the @Value
annotation, is there any way to check (other than if-statements) if spring failed to do the injection and defaulted to null? Say, for example, you're doing it for 10+ variables; it would be rather extensive to go through the chain of if-statements. My intention is to track which failed, and throw an exception listing them. If possible, I'd rather not use reflection but I wouldn't mind if it was cleaner than a chain of if-statements.
UPDATE
Here's an example:
@Value("${my.package.username:#{null}}")
private String username;
When my.package.username
isn't defined for Spring as my.package.username=someUserName
in application.properties
or as a JVM argument for Tomcat to pick it up in the form of
-Dmy.package.username=someUserName
then it should default to null
, which it does. Now, imagine there are 10+ of the above declaration for different variables, I would like to know how to determine which are null
without checking each one. I was thinking there may be functionality in Spring to determine which failed since spring is doing the injection.