Except for the pre-defined "bytype", "byname", "byqualifiedname", "autodetect" modes, Nuts allow custom auto-wiring mode to be registered.
This is useful when a non-standard auto wiring mode is desired.
For example, as specified by EJB 3, a jndi naming service or EJBContext may be used to auto-wire dependencies, so that the "balance" property of "com.mycompany.BankAccount" class can look up "java:comp/env/com/mycompany/BankAccount/balance" from the jndi registry.
Further more, we may also check annotation on the properties so that explicitly specified lookup key overrides the default naming convention specified by EJB 3 specification.
The pseudo code to create such auto wiring rule is:
An instance of this class can then be registered into the NutsProcessor object using the "registerAutoWiring()" method so that it can be used as an auto wiring mode:
This auto wiring mode can then be used in xml configuration file such that:
Each property of BankAccount will be examined, and those with "@injectMe" annotation will be injected using the value found in the jndi context.
It is also possible to have Nuts configure the jndi Context as well, for example, we could auto wire the Context object by type:
Thus, we do not have to provide the Context object, it can be configured by the configuration file:
The code to register the auto wiring mode becomes:
