Broadleaf has nearly a thousand service, repository, web, and utility components that each can
be easily extended as needed for custom business logic and functionality. These are configured
as spring beans through normal Spring Configuration mechanisms.
Broadleaf out of box beans use the following syntax which so that out of box functionality will
back off if your application defines a configuration for the same bean. For example, here is the
snippet of configuration that registers the out of box ProductService
.
@Configuration
public class CatalogServiceAutoConfiguration {
// ...
@Bean
@ConditionalOnMissingBean
ProductService<Product> productService(
ProductRepository<Trackable> productRepository,
RsqlCrudEntityHelper helper,
VariantService<Variant> variantService) {
return new DefaultProductService<>(productRepository, helper, variantService);
}
// ...
The code above may be a little cryptic if you are new to Spring configuration but there are
two important parts to callout. First, notice the line where the service is constructed with
new DefaultProductService(…)
. An implementation could create its own configuration that
constructed an extension of the DefaultProductService
to add, overrride, or replace out of box
functionality.
This works because we use the @ConditionalOnMissingBean
spring annotation which means that your
bean configuration will always take priority over the out of box configuration.