Not able to configure swagger with jax-rs webservices
Hi,
I had some experience with swagger and configured swagger very easily in one of my project which was in springboot.
But I need to configure swagger to a project where all the APIs/ webservices are written with jersey APIs (javax.ws.rs) (version 1.1.1)
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
Link from where code is referred: https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-Jersey-1.X-Project-Setup-1.5
Method I used in the current code: Using a custom Application subclass
Error I am getting:
[WARNING[m] FAILED Jersey Spring Web Application: java.lang.NoSuchMethodError: org.reflections.util.ClasspathHelper.forPackage(Ljava/lang/String;[Ljava/lang/ClassLoader;)Ljava/util/Collection;
[WARNING[m] FAILED JettyWebAppContext@132e3594@132e3594/TalisSOA-2.9.32-SNAPSHOT,file:/C:/Dev/ws/git-projects/development-environment/talissoaframework/dist/TalisSOA/target/tmp/webapp/,C:\Dev\ws\git-projects\development-environment\talissoaframework\dist\TalisSOA\target\TalisSOA-2.9.32-SNAPSHOT.war: java.lang.NoSuchMethodError: org.reflections.util.ClasspathHelper.forPackage(Ljava/lang/String;[Ljava/lang/ClassLoader;)Ljava/util/Collection;
[WARNING[m] FAILED ContextHandlerCollection@644e9953: java.lang.NoSuchMethodError: org.reflections.util.ClasspathHelper.forPackage(Ljava/lang/String;[Ljava/lang/ClassLoader;)Ljava/util/Collection;
[WARNING[m] FAILED HandlerCollection@4115b8a7: java.lang.NoSuchMethodError: org.reflections.util.ClasspathHelper.forPackage(Ljava/lang/String;[Ljava/lang/ClassLoader;)Ljava/util/Collection;
[[1;31mERROR[m] Error starting handlers
[1;31mjava.lang.NoSuchMethodError[m: [1;31morg.reflections.util.ClasspathHelper.forPackage(Ljava/lang/String;[Ljava/lang/ClassLoader;)Ljava/util/Collection;[m
io.swagger.jaxrs.config.BeanConfig.classes ([1mBeanConfig.java:197[m)
io.swagger.jaxrs.config.BeanConfig.setScan ([1mBeanConfig.java:170[m)
com.talis.soa.jersey.SwaggerApplication.<init> ([1mSwaggerApplication.java:20[m)
sun.reflect.NativeConstructorAccessorImpl.newInstance0 ([1mNative Method[m)
sun.reflect.NativeConstructorAccessorImpl.newInstance ([1mNativeConstructorAccessorImpl.java:62[m)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance ([1mDelegatingConstructorAccessorImpl.java:45[m)
java.lang.reflect.Constructor.newInstance ([1mConstructor.java:423[m)
java.lang.Class.newInstance ([1mClass.java:442[m)
com.sun.jersey.core.spi.component.ComponentConstructor._getInstance ([1mComponentConstructor.java:193[m)
com.sun.jersey.core.spi.component.ComponentConstructor.getInstance ([1mComponentConstructor.java:180[m)
com.sun.jersey.core.spi.component.ProviderFactory.__getComponentProvider ([1mProviderFactory.java:166[m)
com.sun.jersey.core.spi.component.ProviderFactory._getComponentProvider ([1mProviderFactory.java:159[m)
com.sun.jersey.core.spi.component.ioc.IoCProviderFactory._getComponentProvider ([1mIoCProviderFactory.java:116[m)
com.sun.jersey.core.spi.component.ProviderFactory.getComponentProvider ([1mProviderFactory.java:153[m)
com.sun.jersey.server.impl.application.DeferredResourceConfig$ApplicationHolder.<init> ([1mDeferredResourceConfig.java:86[m)
com.sun.jersey.server.impl.application.DeferredResourceConfig$ApplicationHolder.<init> ([1mDeferredResourceConfig.java:79[m)
com.sun.jersey.server.impl.application.DeferredResourceConfig.getApplication ([1mDeferredResourceConfig.java:76[m)
com.sun.jersey.server.impl.application.WebApplicationImpl._initiate ([1mWebApplicationImpl.java:1164[m)
com.sun.jersey.server.impl.application.WebApplicationImpl.access$700 ([1mWebApplicationImpl.java:180[m)
com.sun.jersey.server.impl.application.WebApplicationImpl$13.f ([1mWebApplicationImpl.java:799[m)
com.sun.jersey.server.impl.application.WebApplicationImpl$13.f ([1mWebApplicationImpl.java:795[m)
com.sun.jersey.spi.inject.Errors.processWithErrors ([1mErrors.java:193[m)
com.sun.jersey.server.impl.application.WebApplicationImpl.initiate ([1mWebApplicationImpl.java:795[m)
com.sun.jersey.spi.spring.container.servlet.SpringServlet.initiate ([1mSpringServlet.java:117[m)
com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate ([1mServletContainer.java:339[m)
com.sun.jersey.spi.container.servlet.WebComponent.load ([1mWebComponent.java:605[m)
com.sun.jersey.spi.container.servlet.WebComponent.init ([1mWebComponent.java:207[m)
com.sun.jersey.spi.container.servlet.ServletContainer.init ([1mServletContainer.java:394[m)
com.talis.soa.jersey.CustomJerseyServlet.init ([1mCustomJerseyServlet.java:16[m)
com.sun.jersey.spi.container.servlet.ServletContainer.init ([1mServletContainer.java:577[m)
javax.servlet.GenericServlet.init ([1mGenericServlet.java:241[m)
org.eclipse.jetty.servlet.ServletHolder.initServlet ([1mServletHolder.java:421[m)
org.eclipse.jetty.servlet.ServletHolder.doStart ([1mServletHolder.java:245[m)
org.eclipse.jetty.util.component.AbstractLifeCycle.start ([1mAbstractLifeCycle.java:55[m)
org.eclipse.jetty.servlet.ServletHandler.initialize ([1mServletHandler.java:699[m)
org.eclipse.jetty.servlet.ServletContextHandler.startContext ([1mServletContextHandler.java:193[m)
org.eclipse.jetty.webapp.WebAppContext.startContext ([1mWebAppContext.java:978[m)
org.eclipse.jetty.server.handler.ContextHandler.doStart ([1mContextHandler.java:586[m)
org.eclipse.jetty.webapp.WebAppContext.doStart ([1mWebAppContext.java:349[m)
org.mortbay.jetty.plugin.JettyWebAppContext.doStart ([1mJettyWebAppContext.java:102[m)
org.eclipse.jetty.util.component.AbstractLifeCycle.start ([1mAbstractLifeCycle.java:55[m)
org.eclipse.jetty.server.handler.HandlerCollection.doStart ([1mHandlerCollection.java:165[m)
org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart ([1mContextHandlerCollection.java:162[m)
org.eclipse.jetty.util.component.AbstractLifeCycle.start ([1mAbstractLifeCycle.java:55[m)
org.eclipse.jetty.server.handler.HandlerCollection.doStart ([1mHandlerCollection.java:165[m)
org.eclipse.jetty.util.component.AbstractLifeCycle.start ([1mAbstractLifeCycle.java:55[m)
org.eclipse.jetty.server.handler.HandlerWrapper.doStart ([1mHandlerWrapper.java:92[m)
org.eclipse.jetty.server.Server.doStart ([1mServer.java:228[m)
org.mortbay.jetty.plugin.JettyServer.doStart ([1mJettyServer.java:69[m)
org.eclipse.jetty.util.component.AbstractLifeCycle.start ([1mAbstractLifeCycle.java:55[m)
org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty ([1mAbstractJettyMojo.java:433[m)
org.mortbay.jetty.plugin.AbstractJettyMojo.execute ([1mAbstractJettyMojo.java:377[m)
org.mortbay.jetty.plugin.JettyRunWarMojo.execute ([1mJettyRunWarMojo.java:68[m)
org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo ([1mDefaultBuildPluginManager.java:137[m)
org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 ([1mMojoExecutor.java:370[m)
org.apache.maven.lifecycle.internal.MojoExecutor.doExecute ([1mMojoExecutor.java:351[m)
org.apache.maven.lifecycle.internal.MojoExecutor.execute ([1mMojoExecutor.java:215[m)
org.apache.maven.lifecycle.internal.MojoExecutor.execute ([1mMojoExecutor.java:171[m)
org.apache.maven.lifecycle.internal.MojoExecutor.execute ([1mMojoExecutor.java:163[m)
org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject ([1mLifecycleModuleBuilder.java:117[m)
org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject ([1mLifecycleModuleBuilder.java:81[m)
org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build ([1mSingleThreadedBuilder.java:56[m)
org.apache.maven.lifecycle.internal.LifecycleStarter.execute ([1mLifecycleStarter.java:128[m)
org.apache.maven.DefaultMaven.doExecute ([1mDefaultMaven.java:294[m)
org.apache.maven.DefaultMaven.doExecute ([1mDefaultMaven.java:192[m)
org.apache.maven.DefaultMaven.execute ([1mDefaultMaven.java:105[m)
org.apache.maven.cli.MavenCli.execute ([1mMavenCli.java:960[m)
org.apache.maven.cli.MavenCli.doMain ([1mMavenCli.java:293[m)
org.apache.maven.cli.MavenCli.main ([1mMavenCli.java:196[m)
sun.reflect.NativeMethodAccessorImpl.invoke0 ([1mNative Method[m)
sun.reflect.NativeMethodAccessorImpl.invoke ([1mNativeMethodAccessorImpl.java:62[m)
sun.reflect.DelegatingMethodAccessorImpl.invoke ([1mDelegatingMethodAccessorImpl.java:43[m)
java.lang.reflect.Method.invoke ([1mMethod.java:498[m)
org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced ([1mLauncher.java:282[m)
org.codehaus.plexus.classworlds.launcher.Launcher.launch ([1mLauncher.java:225[m)
org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode ([1mLauncher.java:406[m)
org.codehaus.plexus.classworlds.launcher.Launcher.main ([1mLauncher.java:347[m)
I tried upgrading the swagger-core version from 1.5.0 to 1.5.6 but no luck.
I searched about this error and found out this google chat group : https://groups.google.com/g/swagger-swaggersocket/c/ZtNe0v4S6DA and followed all the steps. But still same issue.
Can someone please help?
web.xml:
<servlet>
<servlet-name>Jersey Spring Web Application</servlet-name>
<servlet-class>com.talis.soa.jersey.CustomJerseyServlet</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.talis.soa.jersey.SwaggerApplication</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
<param-value>com.sun.jersey.api.container.filter.GZIPContentEncodingFilter</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
<param-value>com.sun.jersey.api.container.filter.GZIPContentEncodingFilter</param-value>
</init-param>
<!-- Jackson mapping -->
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>org.codehaus.jackson.jaxrs</param-value>
</init-param>
<load-on-startup>10</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Spring Web Application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
pom.xml
custom application class:
Class where webservice is written:
@Path("/services/release-info")
Singleton
public class ReleaseInfoJersey {
private ReleaseInfoService releaseInfoService;
/**
* @return the releaseInfoService
*/
public ReleaseInfoService getReleaseInfoService() {
return releaseInfoService;
}
/**
* Param releaseInfoService the releaseInfoService to set
*/
public void setReleaseInfoService(ReleaseInfoService releaseInfoService) {
this.releaseInfoService = releaseInfoService;
}
/**
* Release info Jersey method wrapper.
* @return release info
* @throws BusinessServicesException
*/
@RESTDoc("This service returns release info values.")
@GET
@ApiOperation(value = "Get Release info")
@Produces({"application/xml","text/xml","application/json"})
public ReleaseInfo releaseInfo() throws BusinessServicesException {
return releaseInfoService.getReleaseInfo();
}
}