question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Springfox swagger2 @Component does not get indexed by Spring Framework 5 `spring-context-indexer`

See original GitHub issue

Springfox Swagger Version

2.8.0

Spring Boot Version

2.0.2.RELEASE

Description

When using component-indexer with springfox-swagger2, the application fails to start.

Error:

Parameter 2 of method swagger2ControllerMapping in springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration 
required a bean of type 'springfox.documentation.swagger2.mappers.ServiceModelToSwagger2Mapper' 
that could not be found.

Test case

https://github.com/ssouris/swagger-component-indexer-bug

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:12
  • Comments:21 (6 by maintainers)

github_iconTop GitHub Comments

11reactions
mhyeon-leecommented, Nov 8, 2018

@Diagoras

I mean, For compatibility with spring-context-indexer, the Swagger configuration should be modified.

@Configuration
@Import({ SpringfoxWebMvcConfiguration.class, SwaggerCommonConfiguration.class })
//  TODO: remove below: componentScan of external library does not work when using spring-context-indexer. 
//  @ComponentScan(basePackages = { 
//     "springfox.documentation.swagger2.mappers"
//  })   
//   
@ConditionalOnWebApplication
public class Swagger2DocumentationConfiguration {
 
    // TODO:  Add all the @Components under "springfox.documentation.swagger2.mappers" as beans.
     @Bean
     public ModelMapper modelMapper() {
         return new ModelMapperImpl();
     }  

     @Bean
     public ParameterMapper parameterMapper() {
         return new ParameterMapperImpl();
     }  

     @Bean
     public SecurityMapper securityMapper() {
         return new SecurityMapperImpl();
     }  

     @Bean
     public LicensMapperImpl licenseMapper() {
         return new LicenseMapperImpl();
     }
   
     @Bean
     public  VendorExtensionMapper vendorExtensionMapper() {
          return new VendorExtensionsMapperImpl();  
     }

    @Bean
  public ServiceModelToSwagger2Mapper serviceModelToSwagger2Mapper(
     ModelMapper modelMapper,
     ParameterMapper parameterMapper,
     SecurityMapper securityMapper,
     LicenseMapper licenseMapper,
     VendorExtensionMapper vendorExtensionMapper) {
          return new ServiceModelToSwagger2MapperImpl(modelMapper, parameterMapper, securityMapper, licenseMapper, vendorExtensionMapper);
     }
}

In addition, @Components under the following packages may require @Bean registration.

  • SpringfoxWebMvcConfiguration.java

    springfox.documentation.spring.web.scanners springfox.documentation.spring.web.readers.operation springfox.documentation.spring.web.readers.parameter springfox.documentation.spring.web.plugins springfox.documentation.spring.web.paths

  • ModelConfiguration

    springfox.documentation.schema

  • SwaggerCommonConfiguration

    springfox.documentation.swagger.schema springfox.documentation.swagger.readers springfox.documentation.swagger.web


I hope to fix this setting in swagger.

Otherwise, all @Components in the above package must be registered by the developer directly with @Bean.

9reactions
wreulickecommented, Apr 13, 2019

@dilipkrish cc: @ssouris @nathanmauro I wrote a PR for this issue. Could you review it?

https://github.com/springfox/springfox/pull/2971

Read more comments on GitHub >

github_iconTop Results From Across the Web

spring-context-indexer with Swagger 3 - java - Stack Overflow
If I remove the spring-context-indexer dependency from all maven modules, the swagger ui works. How can I solve this issue? (we use spring ......
Read more >
swagger-springmvc - Bountysource
At PUT endpoints I would like to hide id property whereas display at GET ... Springfox swagger2 @Component does not get indexed by...
Read more >
Spring 5 candidate component index case study - AUTO1 Group
While investigating the startup times of our applications, we have identified classpath component scanning as a potential place to look for improvements.
Read more >
Oct 2017 - spring-projects/spring-boot - Gitter
does any of you remember that? Andy Wilkinson. @wilkinsona. Oct 31 2017 09:08 UTC. It's part of Spring Framework. spring-context-indexer.
Read more >
Spring Candidate Component Index - Home | Java By Examples
Firstly, we'll add the spring-context-indexer Maven dependency: ... want to use component indexing, all modules of our application must have an index file....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found