Spring Boot + Springbox swagger error
I have a spring boot project want to integrate with swagger via springbox.
I have my spring boot app up and running all good.
However after I added springbox, it can not pass unit test.
Here are the details I added in project.
위해서pom.xml
,추가된
<!--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 a swagger config 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();
}
}
실행할 때 발생하는 오류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: {}
the version I am using is
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
</parent>
Been looking into this problem for the while morning without luck, then posted this question. Just after posted the question, I found out the solution for this..... (I blame on the not-so-good morning coffee)
제거만 하면 됩니다.@Configuration
swagger configuration 클래스의 주석.
Here is the link I refer to
https://github.com/springfox/springfox/issues/462
I was facing the exact same issue. Here is the solution.
Add this to application-test.properties (Create one if not already present)
spring.profiles.active=test
Annotate the test (if not already present)
@TestPropertySource(locations = "classpath:application-test.properties")
Create a new Swagger Configuration class and annotate it as following:
@Configuration
@EnableSwagger2
@Profile("!test")
public class SwaggerConfig {
@Bean
public Docket api() {
.........
}
}
This will make sure that swagger config is not loaded for test at all.
Add a Profile annotation as below
@Profile("dev")
@Configuration
@EnableSwagger2
public class SwaggerConfig {
so that swagger is not loaded this class not invoked during the compile/build/test life cycle and Add the below property to application-test.properties (Create one if not already present under src/test/resources folder) spring.profiles.active=test resolved the issue for me.
ReferenceURL : https://stackoverflow.com/questions/32449612/spring-boot-springbox-swagger-error
'IT' 카테고리의 다른 글
바니쉬 + nginx SSL + woocmerce - wc-ajax가 작동하지 않음 (0) | 2023.10.10 |
---|---|
HTTP 요청에서 각도 상대 경로 (0) | 2023.10.10 |
null >= 0 & & null <= 0>인데 null == 0이 아닌 이유는 무엇입니까? (0) | 2023.10.10 |
대소문자를 구분하지 않는 PowerShell 교체 (0) | 2023.10.10 |
MySQL에서 LIMIT 1 사용 (0) | 2023.10.10 |