Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm trying to implement Swagger using the JHipster implementation as reference into my Kotlin application.

However, when I run my tests, I get the following error for most of my tests (these tests work fine if I remove this swagger code):

Caused by:
    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'pageableParameterBuilderPlugin' defined in class path resource [com/application/config/apidoc/SwaggerPluginsAutoConfiguration$SpringPagePluginConfiguration.class]: Unsatisfied dependency expressed through method 'pageableParameterBuilderPlugin' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'springfox.documentation.schema.TypeNameExtractor' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

My SwaggerPluginsAutoConfiguration class:

@Configuration
@ConditionalOnWebApplication
@ConditionalOnBean(Docket::class)
@AutoConfigureAfter(SwaggerAutoConfiguration::class)
class SwaggerPluginsAutoConfiguration {
    @Configuration
    @ConditionalOnClass(Pageable::class)
    class SpringPagePluginConfiguration {
        @Bean
        @ConditionalOnMissingBean
        fun pageableParameterBuilderPlugin(typeNameExtractor: TypeNameExtractor,
                                           typeResolver: TypeResolver): PageableParameterBuilderPlugin {
            return PageableParameterBuilderPlugin(typeNameExtractor, typeResolver)

The SwaggerAutoConfiguration class:

@Configuration
@ConditionalOnWebApplication
@ConditionalOnClass(ApiInfo::class, BeanValidatorPluginsConfiguration::class, Servlet::class, DispatcherServlet::class)
@Profile(value = [SPRING_PROFILE_SWAGGER])
@EnableSwagger2
@Import(BeanValidatorPluginsConfiguration::class)
class SwaggerAutoConfiguration(applicationProperties: ApplicationProperties) {

If I include the swagger profile in my tests application config file, the tests pass. However, if the profile isn't present, the tests fail with the error above. I'm not sure why Spring is trying to configure swagger if the profile isn't set.

How can I set this up, so that the configuration doesn't try to load if the profile isn't specified?

See if adding @ComponentScan({"springfox.documentation.schema"}) works until you figure out the proper way to configure this. – Neo Dec 23, 2018 at 23:00 Looking at the Java doc, you may rather add @Import(springfox.documentation.schema.configuration.ModelsConfiguration) to your SwaggerPluginsAutoConfiguration class. – Neo Dec 23, 2018 at 23:14 @Neo When I add @Import(springfox.documentation.schema.configuration.ModelsConfiguration) I get Classifier 'ModelsConfiguration' does not have a companion object, and thus must be initialized here. The issue I'm having only happens on my existing tests. The application starts up normally. Can I do something in the JUnit tests to inject the TypeNameExtractor bean? – Jerry Dec 24, 2018 at 3:39

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.