rest - How to integrate Swagger with Maven + Java + Jersey +Tomcat -
i can't seem understand how integrate swagger generate api documentation. url: ####:8080/myservice/rest/users/getall
have added annotations code , dependency.
try visit: ####:8080/myservice/rest/ says not found.
//web.xml
<servlet> <servlet-name>mycompany-users-serlvet</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.servletcontainer</servlet-class> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>com.users.services.mycompany,com.wordnik.swagger.jersey.listing</param-value> </init-param> ` <servlet> <servlet-name>jerseyjaxrsconfig</servlet-name> <servlet-class>com.wordnik.swagger.jersey.config.jerseyjaxrsconfig</servlet-class> <init-param> <param-name>api.version</param-name> <param-value>1.0.0</param-value> </init-param> <init-param> <param-name>swagger.api.basepath</param-name> <param-value>####:8080/myservice/rest/</param-value> //not sure should be? </init-param> <load-on-startup>2</load-on-startup>`
provided have correctly copied files https://github.com/wordnik/swagger-ui project (directory dist
must copied src/main/webapp
), can access api documentation on http://.../myservice/index.html
. don't forget modify index.html
swagger knows load api docs:
window.swaggerui = new swaggerui({ url: "http://localhost:8080/myservice/rest/api-docs",
the api base path in web.xml
must set http://.../myservice/rest
if rest
application path have defined in implementation of class javax.ws.rs.core.application
using annotation @applicationpath
.
here example of (i don't use web.xml
configuration):
@applicationpath( "api" ) public class myrestapplication extends application { @override public set<class<?>> getclasses( ) { set<class<?>> resources = new hashset<class<?>>( ); resources.add( apilistingresource.class ); resources.add( apideclarationprovider.class ); resources.add( apilistingresourcejson.class ); resources.add( resourcelistingprovider.class ); resources.add( ping.class ); // own resource class swaggerconfiguration( ); return resources; } private void swaggerconfiguration( ) { swaggerconfig swaggerconfig = new swaggerconfig( ); configfactory.setconfig( swaggerconfig ); swaggerconfig.setapiversion( "0.0.1" ); swaggerconfig.setbasepath( "http://localhost:8080/myservice/api" ); scannerfactory.setscanner( new defaultjaxrsscanner( ) ); classreaders.setreader( new defaultjaxrsapireader( ) ); } }
Comments
Post a Comment