This is my first time on here. So we have an application built in Spring MVC handling REST calls with 2 java classes serving as the controller(s). One of them is explicitly annotated with @Controller while the other is annotated with @Component. (2 slightly different ways to defining our routes)
The issue we are facing is that despite our configuration/setup, we are only seeing an empty UI with no endpoints and documentation filled out. It's basically a blank canvas. We did a good amount of searching and despite trying out multiple configurations of beans and definitions, we were still running into the same issue.
Most recently we tried out this example : Swagger Springfox Configuration Issue
Some snippets of our setup/configuration and relevant files are produced below.
Controller(s) classes:
UserDeviceAuthenticationController
@RestController
public class UserDeviceAuthenticationController {
private static final Logger LOGGER = Logger
.getLogger(UserDeviceAuthenticationController.class);
/**
*
* @param response
* @param request
* @param deviceID: a misnomer. This field is different for every client set up on Fitbit
* @throws IOException
* @throws ParseException
*/
@RequestMapping(value = "/fitbitEndPoint", method = RequestMethod.POST)
public void fitbitEndPoint(HttpServletResponse response,
//Body logic redacted
}
PHDDeviceRestService
@Path("device/v2.0")
@Component
public class PHDDeviceRestService extends BaseServiceImpl {
@POST
@Path("/{deviceId}/url")
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_JSON })
public Response getDeviceURL(GetDeviceURLRequest getDeviceURLRequest, @PathParam("deviceId") Long deviceId) throws PHDWebServiceException {
//Logic redacted
}
Configuration Files :
Our relevant Swagger Springfox Dependencies in our Pom.xml
<!-- Swagger dependency -->
<dependencies>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.0</version>
</dependency>
</dependencies>
Our web.xml containing the servlets and url patterns:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc/webmvc-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map all *.spring requests to the DispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/devices/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/healthyweight/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/DevicesGateway/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>jersey</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.uhg.phd.rest;com.uhg.phd.rest.MongoDB</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>CXFSevlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFSevlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CXFSevlet</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>
<!-- <servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> -->
<servlet-mapping>
<servlet-name>CXFSevlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- <servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/swagger-ui.html</url-pattern>
</servlet-mapping> -->
</web-app>
Our SwaggerConfig class where Docket Bean is defined :
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
Our WebMvcConfig class with ViewControllers and ResourceHandlers :
@EnableWebMvc
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addRedirectViewController("/documentation/v2/api-docs", "/v2/api-docs?group=restful-api");
registry.addRedirectViewController("/documentation/swagger-resources/configuration/ui","/swagger-resources/configuration/ui");
registry.addRedirectViewController("/documentation/swagger-resources/configuration/security","/swagger-resources/configuration/security");
registry.addRedirectViewController("/documentation/swagger-resources", "/swagger-resources");
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("documentation/swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("documentation/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
Thank you for reading through all of this. Let me know if you would like to see anymore of our code/files or if I'm missing anything. Any input is appreciated!