Skip to content

@DataMongoTest tries to setup swagger when @EnableSwagger2 exist on application #8670

@barbakini

Description

@barbakini

Hi,

i am using spring boot 1.5.2.RELEASE and mongodb. i wrote some tests with annotation @DatamongoTest and was everything fine. it set up embedded mongo db and autowired my repository classes. But after I add swagger to my project my test fails with the below error:

"Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'documentationPluginsBootstrapper' defined in URL [jar:file:/C:/Users/barbakini/.m2/repository/io/springfox/springfox-spring-web/2.6.1/springfox-spring-web-2.6.1.jar!/springfox/documentation/spring/web/plugins/DocumentationPluginsBootstrapper.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcRequestHandlerProvider' defined in URL [jar:file:/C:/Users/barbakini/.m2/repository/io/springfox/springfox-spring-web/2.6.1/springfox-spring-web-2.6.1.jar!/springfox/documentation/spring/web/plugins/WebMvcRequestHandlerProvider.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.util.List<org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}"

I tricked it with adding two mockbean to my test class but i believe this shouldn't be necessary. You can find additional info below:

Application class:

@SpringBootApplication
@EnableSwagger2
public class ParameterApplication {.....}

Test Class:

@RunWith(SpringRunner.class)
@DataMongoTest
public class ParameterRepositoryTest {

    @MockBean
    private RequestMappingInfoHandlerMapping RequestMappingInfoHandlerMapping;
    @MockBean
    private ServletContext ServletContext;

    @Autowired
    private ParameterRepository parameterRepository;

}

ParameterRepository:

@Repository
public interface ParameterRepository extends MongoRepository<Parameter, String>, MongoTemplateRepository  {
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions