I frequently have applications that require template changes (new user requirements) with no changes to the actual service code. Currently, all of my freemarker templates are sourced from the classpath of my service, but this means I need to rebuild my service every single time. The configurations to my service are externalized by spring cloud config. I really think these freemarker templates could be treated as external resources and imported via the config server. What I would like is for
public Object findTemplateSource(String name){ ... }
from TemplateLoader
to pull the Resource
from the server and then the remainder of the freemarker integration is just like SpringTemplateLoader
.
Client code like BinaryResourceConfigClient
from spring cloud services connectors seems like a good candidate to get this done, but I would love to get people's opinion whether this approach makes sense and how to avoid spring-boot having explicit dependencies in cloud config.
Comment From: scottfrederick
I can see the benefit of this idea, but the issue is misplaced. Spring Cloud builds on top of Spring Boot, so Boot should not depend on any functionality provided by Spring Cloud.
SpringTemplateLoader
is provided by Spring Framework, and relies on the Spring Resource abstraction to load templates. The Spring Resource abstraction includes support for HTTP[S] URLs. It should be possible to configure SpringTemplateLoader
to load templates from a Spring Cloud Config server's plain-text file endpoint using Spring Boot configuration like
spring.freemarker.template-loader-path=classpath:/templates/,https://my-config-server.example.com/myapp/default/master/templates/
If access to the config server requires additional code for authentication (as is the case with the Spring Cloud Services Connectors example), then such code belongs in Spring Cloud or in a separate project, not in Spring Boot.