Unable to bring up swagger-ui from spring-boot application -
i have spring boot application running using embedded tomcat server. partially successful in getting springfox-swagger integrated app. if /v2/api-docs , able see documentation of api's in webapp. however, when trying access same ui, not work. below detailed results.
output of - localhost:8080/api/swagger-resources
[ { "name" : "default", "location" : "/v2/api-docs", "swaggerversion" : "2.0" } ]
output of - localhost:8080/api/v2/api-docs
i valid results. can confirm , output large paste here
but when try access swagger-ui, not work. below different url's invoked access swagger-ui.
http://localhost:8080/swagger-ui.html - ui loading, no documentation of api's present http://localhost:8080/api/swagger-ui.html - 404 not found http://localhost:8080/springfox - 404 not found http://localhost:8080/api/springfox - 404 not found
below swaggerconfig.java class
package com.vmware.vrack.lcm; import org.springframework.context.annotation.bean; import org.springframework.context.annotation.configuration; import springfox.documentation.builders.requesthandlerselectors; import springfox.documentation.service.apiinfo; import springfox.documentation.spi.documentationtype; import springfox.documentation.spring.web.plugins.docket; import springfox.documentation.swagger.web.uiconfiguration; import springfox.documentation.swagger2.annotations.enableswagger2; import static springfox.documentation.builders.pathselectors.regex; @configuration @enableswagger2 public class swaggerconfig { @bean public docket api() { return new docket(documentationtype.swagger_2) .select() .apis(requesthandlerselectors.any()) .paths(regex("/.*")) .build() .apiinfo(apiinfo()); } private apiinfo apiinfo() { apiinfo apiinfo = new apiinfo( "my project's rest api", "this description of api.", "version-1", "api tos", "me@wherever.com", "api license", "api license url" ); return apiinfo; } }
below swagger dependencies using
<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>
below message converter webconfig file
@configuration @enablewebmvc public class webconfig extends webmvcconfigureradapter { @override public void configuremessageconverters(list<httpmessageconverter<?>> converters) { converters.add(jackson2converter()); } @bean public mappingjackson2httpmessageconverter jackson2converter() { mappingjackson2httpmessageconverter converter = new mappingjackson2httpmessageconverter(); converter.setobjectmapper(objectmapper()); return converter; } @bean public objectmapper objectmapper() { objectmapper objectmapper = new objectmapper(); objectmapper.enable(serializationfeature.indent_output); return objectmapper; } }
the below link says @enablewebmvc should not used in spring-boot webapp , using annotation might cause issues in bringing swagger-ui up. but, if not use annotation, web-app not coming (i have pasted error stack trace below)
http://springfox.github.io/springfox/docs/current/#configuring-the-objectmapper
error trace when don't use @enablewebmvc annotation
org.springframework.beans.factory.unsatisfieddependencyexception: error creating bean name 'documentationpluginsbootstrapper' defined in url [jar:file:/users/ngorijala/.m2/repository/io/springfox/springfox-spring-web/2.2.2/springfox-spring-web-2.2.2.jar!/springfox/documentation/spring/web/plugins/documentationpluginsbootstrapper.class]: unsatisfied dependency expressed through constructor argument index 1 of type [springfox.documentation.spi.service.requesthandlerprovider]: : error creating bean name 'webmvcrequesthandlerprovider' defined in url [jar:file:/users/ngorijala/.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 index 0 of type [java.util.list]: : no qualifying bean of type [org.springframework.web.servlet.mvc.method.requestmappinginfohandlermapping] found dependency [collection of org.springframework.web.servlet.mvc.method.requestmappinginfohandlermapping]: expected @ least 1 bean qualifies autowire candidate dependency. dependency annotations: {}; nested exception org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type [org.springframework.web.servlet.mvc.method.requestmappinginfohandlermapping] found dependency [collection of org.springframework.web.servlet.mvc.method.requestmappinginfohandlermapping]: expected @ least 1 bean qualifies autowire candidate dependency. dependency annotations: {}; nested exception org.springframework.beans.factory.unsatisfieddependencyexception: error creating bean name 'webmvcrequesthandlerprovider' defined in url [jar:file:/users/ngorijala/.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 index 0 of type [java.util.list]: : no qualifying bean of type [org.springframework.web.servlet.mvc.method.requestmappinginfohandlermapping] found dependency [collection of org.springframework.web.servlet.mvc.method.requestmappinginfohandlermapping]: expected @ least 1 bean qualifies autowire candidate dependency. dependency annotations: {}; nested exception org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type [org.springframework.web.servlet.mvc.method.requestmappinginfohandlermapping] found dependency [collection of org.springframework.web.servlet.mvc.method.requestmappinginfohandlermapping]: expected @ least 1 bean qualifies autowire candidate dependency. dependency annotations: {} @ org.springframework.beans.factory.support.constructorresolver.createargumentarray(constructorresolver.java:749) @ org.springframework.beans.factory.support.constructorresolver.autowireconstructor(constructorresolver.java:185) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.autowireconstructor(abstractautowirecapablebeanfactory.java:1139) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbeaninstance(abstractautowirecapablebeanfactory.java:1042) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:504) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:476) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:303) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:230) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:299) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:194) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:755) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:757) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:480) @ org.springframework.web.context.contextloader.configureandrefreshwebapplicationcontext(contextloader.java:403) @ org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:306) @ org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:106) @ org.eclipse.jetty.server.handler.contexthandler.callcontextinitialized(contexthandler.java:799) @ org.eclipse.jetty.servlet.servletcontexthandler.callcontextinitialized(servletcontexthandler.java:499) @ org.eclipse.jetty.server.handler.contexthandler.startcontext(contexthandler.java:790) @ org.eclipse.jetty.servlet.servletcontexthandler.startcontext(servletcontexthandler.java:337) @ org.eclipse.jetty.webapp.webappcontext.startwebapp(webappcontext.java:1343) @ org.eclipse.jetty.maven.plugin.jettywebappcontext.startwebapp(jettywebappcontext.java:296) @ org.eclipse.jetty.webapp.webappcontext.startcontext(webappcontext.java:1336) @ org.eclipse.jetty.server.handler.contexthandler.dostart(contexthandler.java:742) @ org.eclipse.jetty.webapp.webappcontext.dostart(webappcontext.java:499) @ org.eclipse.jetty.maven.plugin.jettywebappcontext.dostart(jettywebappcontext.java:365) @ org.eclipse.jetty.util.component.abstractlifecycle.start(abstractlifecycle.java:68) @ org.eclipse.jetty.util.component.containerlifecycle.start(containerlifecycle.java:132) @ org.eclipse.jetty.util.component.containerlifecycle.dostart(containerlifecycle.java:114) @ org.eclipse.jetty.server.handler.abstracthandler.dostart(abstracthandler.java:61) @ org.eclipse.jetty.server.handler.contexthandlercollection.dostart(contexthandlercollection.java:163)
i have feeling missing trivial. can please take , let me know missing.?? in advance.!!
if want keep @enablewebmvc annotation way, have add following
@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/"); }
Comments
Post a Comment