Spring's need for optional dependencies
Peter Levart
peter.levart at gmail.com
Fri Dec 18 16:02:49 UTC 2015
On 12/18/2015 04:49 PM, Peter Levart wrote:
> You can check whether the optional module is included in a runtime
> configuration or not with a simple Class.forName() check even if you
> don't depend on the module (i.e. don't list it in "requires"
> descriptor at runtime). The visibility of classes is not restricted.
> It only depends on ClassLoader hierarchy. When you successfully
> resolve some optional class at runtime (with Class.forName), you then
> have to add a read edge to it's module:
>
> Class<?> optionalClass = Class.forName("...");
> MySelfClass.getModule().addRead(optionalClass.getModule());
>
> ...before invoking any code that uses this module.
Just had an idea!
Optional dependency at runtime could add a read edge to the module if
that module was included in the configuration, but would otherwise not
cause that module to be included in the configuration by itself. How
does that sound? Spring would work as before - no .addRead() calls
needed. Just Class.forName("OptionalClass").
Regards, Peter
More information about the jigsaw-dev
mailing list