@DataMongoTest tries to setup swagger when @EnableSwagger2 exist on application
See original GitHub issueHi,
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 {
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (1 by maintainers)
Top Results From Across the Web
java - Swagger 2 Issue - Spring Boot - Stack Overflow
Just add this configuration to your application.properties spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER.
Read more >Setting Up Swagger 2 with a Spring REST API - Baeldung
In plain Spring projects, we need to enable Swagger 2 explicitly. To do so, we have to use the @EnableSwagger2WebMvc on our configuration...
Read more >Spring Boot - Enabling Swagger2 - Tutorialspoint
The @EnableSwagger2 annotation is used to enable the Swagger2 for your Spring Boot application. The code for main Spring Boot application is shown...
Read more >Springfox Reference Documentation - GitHub Pages
@Configuration @EnableWebMvc //NOTE: Only needed in a non-springboot application @EnableSwagger2 @ComponentScan("com.myapp.controllers") public ...
Read more >Swagger Annotation and Spring Configuration - Xoriant
To Use plugin, we should create Java configuration class with @Configuration class and define this class in application context file. @EnableSwagger2 public ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

No, I didn’t face that. You should ask in stackoverflow or some other sites. Definitely it is not about any spring related bug so we should not write here.
@barbakini Thanks for all the inputs, I will reach out on stack overflow.