@Target(value={TYPE,METHOD}) @Retention(value=RUNTIME) @Documented @Conditional(value=OnBroadleafModuleCondition.class) public @interface ConditionalOnBroadleafModule
Allows for conditional registration of beans depending only if a particular Broadleaf module is present. By default, this checks for the presence of
an implementation entry for a BroadleafModuleRegistration
in spring.factories
.
There are 2 options for checking these registrations:
value()
which assumes that this class is kept up to date with different modules that are addedmoduleName()
which maps directly to the BroadleafModuleRegistration.getModuleName()
Generally you should use the value()
attribute to give you a type-safe way to reference the registrations but it is possible
that you need to reference a module that has not yet been added to this class. In that case, use the moduleName()
parameter
which allows for more dynamic checking of module names.
If the module has not registered itself via spring.factories
then this will always return false. In this case,
utilize one of the Spring ConditionalOn...
annotations like ConditionalOnClass
and consider making your own composed
annotation that utilizes it. For instance:
@Target({ ElementType.TYPE, ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME) @Documented @ConditionalOnClass("com.broadleafcommerce.somemodule.ModuleClass") public @interface ConditionalOnSomeModule { }
This annotation can be used as a composed meta-annotation for module-specific annotations. Example:
@Target({ ElementType.TYPE, ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME) @Documented @ConditionalOnBroadleafModule(BroadleafModuleEnum.ACCOUNT) public @interface ConditionalOnAccountModule { }
ModulePresentUtil}
Modifier and Type | Optional Element and Description |
---|---|
String |
moduleName
This should only be used if the module you are checking for has not yet been added to the
BroadleafModuleRegistration.BroadleafModuleEnum as that. |
BroadleafModuleRegistration.BroadleafModuleEnum |
value
Which module to check for the presence of.
|
public abstract BroadleafModuleRegistration.BroadleafModuleEnum value
moduleName()
but can be used as as stop-gap measurement if the module is not explicitly defined in BroadleafModuleRegistration.BroadleafModuleEnum
.public abstract String moduleName
BroadleafModuleRegistration.BroadleafModuleEnum
as that.
Generally you should seek to use the value()
parameter and add additional modules as needed.Copyright © 2022. All rights reserved.