我必须将swagger与spring Restful项目集成以生成API文档。
我已按照https://rahulvishwakarma.wordpress.com/2014/06/01/show-off-your-spring-web-services-through-swagger-just-like-that/中的步骤将战争部署到tomcat服务器(http://localhost:8080/sample_swagger)。
在tomcat控制台中运行项目时,它会扫描所有控制器及其服务,但使用浏览器会导致下面显示的错误。 请指导我哪里出错了。
java.lang.NoSuchMethodError: com.wordnik.swagger.model.ApiDescription.<init>(Ljava/lang/String;Lscala/Option;Lscala/collection/immutable/List;Z)V
com.mangofactory.swagger.readers.ApiDescriptionReader.execute(ApiDescriptionReader.java:44)
com.mangofactory.swagger.readers.ApiDescriptionReader.execute(ApiDescriptionReader.java:18)
com.mangofactory.swagger.core.CommandExecutor.execute(CommandExecutor.java:13)
com.mangofactory.swagger.scanners.ApiListingScanner.scan(ApiListingScanner.java:96)
com.mangofactory.swagger.core.SwaggerApiResourceListing.initialize(SwaggerApiResourceListing.java:71)
com.mangofactory.swagger.plugin.SwaggerSpringMvcPlugin.initialize(SwaggerSpringMvcPlugin.java:371)
com.mangofactory.swagger.plugin.SwaggerPluginAdapter.onApplicationEvent(SwaggerPluginAdapter.java:43)
com.mangofactory.swagger.plugin.SwaggerPluginAdapter.onApplicationEvent(SwaggerPluginAdapter.java:21)
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:98)
org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:333)
org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:776)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:485)
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
javax.servlet.GenericServlet.init(GenericServlet.java:160)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
java.lang.Thread.run(Thread.java:722)
项目配置:
java -1.7.0
tomcat -6.0 &7.0
ant -1.9.4
spring -4.0.5
罐:
swagger-annotations-1.3.5.jar
swagger-core_2.10-1.3.5.jar
swagger-models-0.9.2.jar
swagger-springmvc-0.9.2.jar
classmate-0.8.0.jar
guava-18.0.jar
scalaj-collection_2.10-1.5.jar
jackson-databind-2.2.3.jar
休息-servlet.xml中:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.example.sample.controller" />
<mvc:annotation-driven />
<context:annotation-config/>
<mvc:default-servlet-handler/>
<context:property-placeholder location="classpath:swagger.properties" />
<!-- To enable @RequestMapping process on type level and method level -->
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean id="springSwaggerConfig" class="com.mangofactory.swagger.configuration.SpringSwaggerConfig" />
</beans>
swagger.properties:
documentation.services.basePath=http://localhost:8080/sample_swagger
documentation.services.version=2.0