I've implemented a starter that configures Swagger the way I like. In addition, I'd like to redirect every call to the app's root URL (e.g. localhost:8080
) to /swagger-ui.html
.
Therefore, I added an own AbstractEndpoint
which is instantiated in the @Configuration
class as follows:
@Configuration
@Profile("swagger")
@EnableSwagger2
public class SwaggerConfig {
...
@Bean
public RootEndpoint rootEndpoint() {
return new RootEndpoint();
}
@Bean
@ConditionalOnBean(RootEndpoint.class)
@ConditionalOnEnabledEndpoint("root")
public RootMvcEndpoint rootMvcEndpoint(RootEndpoint rootEndpoint) {
return new RootMvcEndpoint(rootEndpoint);
}
}
The respective classes look like this:
public class RootEndpoint extends AbstractEndpoint<String> {
public RootEndpoint() {
super("root");
}
@Override
public String invoke() {
return ""; // real calls shall be handled by RootMvcEndpoint
}
}
and
public class RootMvcEndpoint extends EndpointMvcAdapter {
public RootMvcEndpoint(RootEndpoint delegate) {
super(delegate);
}
@RequestMapping(method = {RequestMethod.GET}, produces = { "*/*" })
public void redirect(HttpServletResponse httpServletResponse) throws IOException {
httpServletResponse.sendRedirect("/swagger-ui.html");
}
}
As stated in public RootEndpoint()
, the custom Endpoint is bound to /root
. Unfortunately, I can't specify super("");
or super("/");
as those values throw an exception (Id must only contains letters, numbers and '_'
).
How can I achieve having a custom Endpoint listening to the root URL in a starter using @Configuration
files to instantiate beans?