У меня есть некоторые веб-сервисы Restful, разработанные на Spring @RestController
и использующие Spring5.0.5. (Это не проект Spring Boot)
Я пытаюсь сгенерировать документацию API, используя Swagger, и для этого я пытаюсь использовать Springfox.
Ниже приведены изменения, которые я внес в проект: -
Добавлено в Pom.xml
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
Создан класс SwaggerConfig.java -
@Configuration
@EnableSwagger2
@EnableAspectJAutoProxy(proxyTargetClass=true)
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("package-name"))
.paths(PathSelectors.any())
.build();
}
}
Примечание: - Я также попытался добавить / удалить @EnableAspectJAutoProxy (proxyTargetClass = true).
AppConfig.java
@EnableWebMvc
public class AppConfig extends WebMvcConfigureAdaptor{
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
Но при использовании http://localhost:port/context-root/v2/api-docs
и http://localhost:port/context-root/v2/swagger-ui.html
я продолжаю получать исключение инициализации Бина -
Ошибка при создании bean-компонента с именем DocumentationPluginsBootStrapper.
Пожалуйста, предложите, где я неправ в реализации.
Я пытался удалить и добавить несколько аннотаций, но пока безуспешно.
Ошибка: -
DispatcherSer E org.springframework.web.servlet.FrameworkServlet initServletBean Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error createion bean with name 'documentationPluginsBootstrapper' defined in URL [wsjar:file:/C:/WebspherePathforWarfile/WEB-INF/lib/springfox-spring-web-2.7.0.jar!/springfox/documentation/spring/web/plugins/DocumentationPluginsBootstrapper.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.UnsatisfiedDependencyException: Error creating bean with name 'webMvcRequestHandlerProvider' defined in URL [wsjar:file:C:/webspeherisntalledapp/WEB-INF/lib/springfox-spring-web2.7.0.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 {}
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:729)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:192)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1270)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:541)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$dogetBean$0(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda.000000002E7527.getObject(unkown source)
......
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
.................
caused by :org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcRequestHandlerProvider' defined in URL [wsjar:file:C:/Webspherinstalledapp/WEB-INF/lib/springfox-spring-web-2.7.0.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: {}
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:729)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:192)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1270)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:541)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$dogetBean$0(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda.000000002E7527.getObject(unkown source)
Обновление. Мне удалось устранить эту ошибку, удалив аннотацию @Configuration из SwaggerConfig.java, но теперь я нахожусь в другой проблеме.
Получение - noHandlerFound При доступе не найдено сопоставление http://localhost:port/context-root/v2/api-docs