You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We do not always know the URL of our deployed applications at build time and as such having the basePath hardcoded as part of the build process doesn't work. Even using maven properties to change the path doesn't help with the application being portable.
The text was updated successfully, but these errors were encountered:
We had the same problem. We're using Spring Boot with embedded Tomcat and got a workaround for this by using an Interceptor, which overrides the jsondoc configuration at runtime, with the hostname given by the request. The interceptor only listens on the jsondoc path. Here's the code (without the imports):
@Component
public class DocumentationInterceptor extends HandlerInterceptorAdapter {
@Inject
private JSONDocProperties jsonDocProperties;
@Inject
private JSONDocController jsonDocController;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
final URL baseURLFromRequest = RequestHelper.getBaseURLFromRequest(request);
jsonDocProperties.setBasePath(baseURLFromRequest.toExternalForm());
final Field basePath = jsonDocController.getClass().getDeclaredField("basePath");
basePath.setAccessible(true);
basePath.set(jsonDocController, jsonDocProperties.getBasePath());
return super.preHandle(request, response, handler);
}
}
And for the config (without imports):
@Configuration
public class DocumentationConfig {
@Bean
public MappedInterceptor mappedInterceptor(DocumentationInterceptor documentationInterceptor) {
return new MappedInterceptor(new String[]{"/jsondoc*"}, documentationInterceptor);
}
}
We do not always know the URL of our deployed applications at build time and as such having the basePath hardcoded as part of the build process doesn't work. Even using maven properties to change the path doesn't help with the application being portable.
The text was updated successfully, but these errors were encountered: