Commit 2c451ad7 by Roy Clarkson

Fix issue where the Hystrix dashboard will not load

Overrides Spring Boot's FreeMarkerAutoConfiguration to prefer using a SpringTemplateLoader instead of the file system. This corrects an issue where Spring Boot may use an empty 'templates' file resource to resolve templates instead of the packaged Hystrix classpath templates. When creating a new project with Spring initializer, an empty 'templates' resource directory is automatically added to the new project, causing a scenario where this issue may occur.
parent 75ff9540
...@@ -21,17 +21,42 @@ import org.apache.http.params.HttpConnectionParams; ...@@ -21,17 +21,42 @@ import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams; import org.apache.http.params.HttpParams;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration;
import org.springframework.boot.context.embedded.ServletRegistrationBean; import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.ui.freemarker.SpringTemplateLoader;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
/** /**
* @author Dave Syer * @author Dave Syer
* @author Roy Clarkson
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Configuration @Configuration
public class HystrixDashboardConfiguration { public class HystrixDashboardConfiguration {
private static final String DEFAULT_TEMPLATE_LOADER_PATH = "classpath:/templates/";
private static final String DEFAULT_CHARSET = "UTF-8";
/**
* Overrides Spring Boot's {@link FreeMarkerAutoConfiguration} to prefer using a
* {@link SpringTemplateLoader} instead of the file system. This corrects an issue
* where Spring Boot may use an empty 'templates' file resource to resolve templates
* instead of the packaged Hystrix classpath templates.
* @return FreeMarker configuration
*/
@Bean
public FreeMarkerConfigurer freeMarkerConfigurer() {
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
configurer.setTemplateLoaderPaths(DEFAULT_TEMPLATE_LOADER_PATH);
configurer.setDefaultEncoding(DEFAULT_CHARSET);
configurer.setPreferFileSystemAccess(false);
return configurer;
}
@Bean @Bean
public ServletRegistrationBean proxyStreamServlet() { public ServletRegistrationBean proxyStreamServlet() {
return new ServletRegistrationBean(new ProxyStreamServlet(), "/proxy.stream"); return new ServletRegistrationBean(new ProxyStreamServlet(), "/proxy.stream");
......
The presence of this templates directory tests the Spring Boot FreeMarker configuration
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment