From 75ff9540bb12540d9ab505fb923f6814e22e7f64 Mon Sep 17 00:00:00 2001 From: Roy Clarkson Date: Tue, 16 Dec 2014 12:28:38 -0600 Subject: [PATCH 1/2] Fix typos in README --- docs/src/main/asciidoc/README.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/main/asciidoc/README.adoc b/docs/src/main/asciidoc/README.adoc index a7543fac..7c28ba98 100644 --- a/docs/src/main/asciidoc/README.adoc +++ b/docs/src/main/asciidoc/README.adoc @@ -10,8 +10,8 @@ include::intro.adoc[] * Circuit Breaker: embedded Hystrix dashboard with declarative Java configuration * Declarative REST Client: Feign creates a dynamic implementation of an interface decorated with JAX-RS or Spring MVC annotations * Client Side Load Balancer: Ribbon -* External Configuration: a bridge from the Sprnig Environment to Archaius (enabls native configuration of Netflix components using Spring Boot conventions) -* Router and Filter: automatic regsitration of Zuul filters,a nd a simple convention over configuration approach to reverse proxy creation +* External Configuration: a bridge from the Sprnig Environment to Archaius (enables native configuration of Netflix components using Spring Boot conventions) +* Router and Filter: automatic regsitration of Zuul filters, and a simple convention over configuration approach to reverse proxy creation == Building From 2c451ad73e70e58f92e85a4225b1d14d8985ca07 Mon Sep 17 00:00:00 2001 From: Roy Clarkson Date: Tue, 16 Dec 2014 15:43:13 -0600 Subject: [PATCH 2/2] 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. --- .../HystrixDashboardConfiguration.java | 25 +++++++++++++++++++ .../src/test/resources/templates/test.txt | 1 + 2 files changed, 26 insertions(+) create mode 100644 spring-cloud-netflix-hystrix-dashboard/src/test/resources/templates/test.txt diff --git a/spring-cloud-netflix-hystrix-dashboard/src/main/java/org/springframework/cloud/netflix/hystrix/dashboard/HystrixDashboardConfiguration.java b/spring-cloud-netflix-hystrix-dashboard/src/main/java/org/springframework/cloud/netflix/hystrix/dashboard/HystrixDashboardConfiguration.java index 3da958e3..4c338016 100644 --- a/spring-cloud-netflix-hystrix-dashboard/src/main/java/org/springframework/cloud/netflix/hystrix/dashboard/HystrixDashboardConfiguration.java +++ b/spring-cloud-netflix-hystrix-dashboard/src/main/java/org/springframework/cloud/netflix/hystrix/dashboard/HystrixDashboardConfiguration.java @@ -21,17 +21,42 @@ import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpParams; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration; import org.springframework.boot.context.embedded.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.ui.freemarker.SpringTemplateLoader; +import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; /** * @author Dave Syer + * @author Roy Clarkson */ @SuppressWarnings("deprecation") @Configuration 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 public ServletRegistrationBean proxyStreamServlet() { return new ServletRegistrationBean(new ProxyStreamServlet(), "/proxy.stream"); diff --git a/spring-cloud-netflix-hystrix-dashboard/src/test/resources/templates/test.txt b/spring-cloud-netflix-hystrix-dashboard/src/test/resources/templates/test.txt new file mode 100644 index 00000000..69d32d57 --- /dev/null +++ b/spring-cloud-netflix-hystrix-dashboard/src/test/resources/templates/test.txt @@ -0,0 +1 @@ +The presence of this templates directory tests the Spring Boot FreeMarker configuration \ No newline at end of file