Spring Boot
Springfox
DocumentationPluginsBootstrapper
Error Resolution
Java Development

Spring Boot 2.6.0 / Spring fox 3 - Failed to start bean 'documentationPluginsBootstrapper'

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Spring Boot 2.6.0 introduced various updates and improvements, but it also led to some compatibility issues with certain libraries. One of the common issues developers encounter is the failure to start the bean documentationPluginsBootstrapper when using Springfox 3 with Spring Boot 2.6. In this article, we will explore the problem in detail and provide possible solutions and workarounds.

Understanding the Problem

Springfox is a popular library for generating API documentation in Spring-based applications. The documentationPluginsBootstrapper is a Springfox bean responsible for bootstrapping documentation plugins. When the application starts, Spring initializes this bean to generate API documentation.

Key Error Message

Developers facing this issue usually see an error message resembling the following:

plaintext
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
...
The bean 'documentationPluginsBootstrapper', defined in URL [jar:file:/path/to/springfox-core-3.0.0.jar!/springfox/documentation/spring/web/plugins/DocumentationPluginsBootstrapper.class], could not be registered. A bean with that name has already been defined.

Root Cause Analysis

The primary cause of this issue is the changes in Spring Boot 2.6.0's internal handling of application contexts and bean registration. These changes disrupt the expected initialization flow of Springfox, leading to bean conflicts.

Important Changes in Spring Boot 2.6.0

  • Path Matching Strategy: Spring Boot 2.6 introduced changes in the default path matching strategy. Instead of using PathPatternParser, it now defaults to AntPathMatcher, which is incompatible with Springfox out of the box.
  • Spring Boot Properties Binding: The change affects Springfox’s initialization, leading to circular dependencies or initialization errors.

Bean Incompatibility

Spring's dependency and bean registration policies became stricter in 2.6.0, able to detect multiple beans matching certain type signatures, which results in conflicts for some pre-existing libraries like Springfox.

Workarounds and Solutions

While a permanent fix may require updates to Springfox, you can apply several workarounds to resolve the conflict:

1. Configure Path Matching Compatibility

Modify your application.properties or application.yml to maintain compatibility with Springfox by using the legacy path matcher:

properties
spring.mvc.pathmatch.matching-strategy=ant-path-matcher

2. Exclude Certain Auto Configurations

Explicitly exclude problematic auto-configurations from Spring Boot that conflict with Springfox:

java
1@SpringBootApplication(exclude = {
2    WebMvcAutoConfiguration.class
3})
4public class MyApplication {
5    public static void main(String[] args) {
6        SpringApplication.run(MyApplication.class, args);
7    }
8}

3. Use Springfox via Spring Boot Starter

Switching to springdoc-openapi, a similar library fully compatible with Spring Boot 2.6, can be a more permanent solution.

xml
1<dependency>
2    <groupId>org.springdoc</groupId>
3    <artifactId>springdoc-openapi-ui</artifactId>
4    <version>1.5.13</version>
5</dependency>

4. Custom Bean Definitions

Manually define any conflicting beans in your application context to avoid automatic bean registration issues:

java
1@Bean
2public DocumentationPluginsBootstrapper documentationPluginsBootstrapper() {
3    return new DocumentationPluginsBootstrapper(...);
4}

Summary Table

IssueDescriptionWorkaround
Bean ConflictdocumentationPluginsBootstrapper conflicts with existing beansDefine custom bean or remove existing bean registrations
Path Matching Strategy IncompatibilitySpring Boot 2.6 changes to path matchingUse legacy ant-path-matcher in configuration
Incompatible Auto ConfigurationSpring Boot's auto configurations clash with SpringfoxExclude certain auto-configurations or use alternative documentation libraries

Additional Resources

These insights and workarounds should help you circumvent the initialization issue with Springfox and Spring Boot 2.6.0, ensuring your application documentation is generated correctly without delays or downtime.


Related reading
Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.