Spring Download Error + Springbox

I have a spring boot project that wants to integrate with swagger through Springbox.

I have my spring boot application and everything works fine.

However, after I added Springbox, it cannot pass the unit test.

Here are the details that I added in the project.

For pom.xml added

  <!--Swagger io for API doc--> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-core</artifactId> <version>1.5.3</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.2.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.2.2</version> </dependency> 

then with the swagger configuration class

 @Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket booksApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.regex("/.*")) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("blah") .description("blah.") .termsOfServiceUrl("http://www.blah.com.au") .contact("blah") .build(); } } 

The error I get when running mvn clean package ,

  org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcRequestHandlerProvider' defined in URL [jar:file:/Users/jasonfeng/.m2/repository/io/springfox/springfox-spring-web/2.2.2/springfox-spring-web-2.2.2.jar!/springfox/documentation/spring/web/plugins/WebMvcRequestHandlerProvider.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [java.util.List]: : No qualifying bean of type [org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping] found for dependency [collection of org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping] found for dependency [collection of org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} 

used version

 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.2.5.RELEASE</version> </parent> 
+7
java spring spring-boot swagger
source share
3 answers

Looking into this problem while unlucky in the morning, then posted this question. Immediately after I posted this question, I found a solution for this ..... (I blame myself for the bad morning coffee)

Just remove the @Configuration annotation in the swagger configuration class.

Here is the link I'm linking to

https://github.com/springfox/springfox/issues/462

+13
source share

I ran into the same problem. Here is the solution.

Add this to application-test.properties (create one if it does not already exist)

 spring.profiles.active=test 

Annotate the test (if not already present)

 @TestPropertySource(locations = "classpath:application-test.properties") 

Create a new Swagger configuration class and mark it as follows:

 @Configuration @EnableSwagger2 @Profile("!test") public class SwaggerConfig { @Bean public Docket api() { ......... } } 

This ensures that the swagger configuration does not load for testing at all.

+4
source share

Add profile annotation below

 @Profile("dev") @Configuration @EnableSwagger2 public class SwaggerConfig { 

so that swagger does not load, this class is not called during the compilation / assembly / testing life cycle and add the property below to application-test.properties (create one if it is not already specified in the src / test / resources folder) spring.profiles.active = test solved the problem for me.

0
source share

All Articles