Forum Discussion
nehakakar
2 years agoOccasional Contributor
Update your MyApp class to include the Swagger UI configuration.
import org.apache.cxf.jaxrs.openapi.OpenApiFeature;
import org.apache.cxf.jaxrs.swagger.ui.SwaggerUiConfig;
public class MyApp extends Application {
// ...
@Override
public Set<Object> getSingletons() {
final OpenApiFeature feature = new OpenApiFeature();
// Set the Swagger UI configuration
SwaggerUiConfig uiConfig = new SwaggerUiConfig()
.url("/webappname/doc/openapi.json") // Set the URL of your swagger.json file
.queryConfigEnabled(true);
feature.setSwaggerUiConfig(uiConfig);
singletons.add(feature);
return singletons;
}
}
In your web.xml, update the servlet and servlet-mapping to map the URL of your Swagger UI.
<servlet>
<display-name>REST API Documentation</display-name>
<servlet-name>RestAPIDoc</servlet-name>
<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
<init-param>
<param-name>jaxrs.serviceClasses</param-name>
<param-value>com.abc.xyz.AgentManagerService</param-value>
</init-param>
<init-param>
<param-name>jaxrs.features</param-name>
<param-value>org.apache.cxf.jaxrs.openapi.OpenApiFeature</param-value>
</init-param>
<init-param>
<param-name>jaxrs.providers</param-name>
<param-value>
org.apache.cxf.jaxrs.provider.MultipartProvider,
com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>RestAPIDoc</servlet-name>
<url-pattern>/doc/*</url-pattern>
</servlet-mapping>
Make sure your swagger.json file is available at the specified URL (/webappname/doc/openapi.json) and contains the correct API definition for your application.
I hope it helps.
Related Content
- 2 years ago
- 6 years ago
- 2 years ago
- 3 years ago
Recent Discussions
- 4 days ago
- 26 days ago