Package org.apache.juneau.rest.server.view.freemarker
juneau-rest-server-view-freemarker
module.
Provides three sibling pieces that together let a Juneau REST resource render Apache FreeMarker templates:
FreemarkerMixin— mixin that renders raw FreeMarker templates from the importer's classpath under/freemarker/*and auto-registersFreemarkerViewRenderer.FreemarkerView— immutable value class (implements the coreViewinterface) returned from@RestOpmethods to ask the framework to render a FreeMarker template.FreemarkerViewRenderer—ResponseProcessorthat detectsFreemarkerViewreturns and dispatches them to the configuredConfigurationviacfg.getTemplate(templateName).process(dataModel, writer).
Composition example (microservice):
Engine-agnostic packaging:
The bridge module's main POM declares only org.freemarker:freemarker in
provided scope — no concrete FreeMarker transitive dep ships here.
Consumers add the engine matching their deployment:
- Juneau microservice / Jetty: add
org.freemarker:freemarker. With no user-supplied configuration bean, the bridge builds a defaultConfigurationon first request anchored on the importer's classpath under the configured base path. - Spring Boot: add
spring-boot-starter-freemarker. Spring Boot autoconfigures afreemarker.template.Configurationbean which the bridge picks up automatically viaBeanStore.getBean(Configuration.class)— no further wiring required. - Custom: register your own
@Bean freemarker.template.Configurationwith whatever loaders / encodings / output formats / template-update policies you need.
When no FreeMarker engine is on the classpath, the renderer surfaces a clear diagnostic
naming the missing dependency and linking to the "Choosing a Configuration" matrix in
FreemarkerViewSupport.md.
.ftl vs .ftlh:
FreeMarker auto-selects HTML escaping by file extension: .ftlh templates emit
HTML-escaped output, while .ftl templates emit raw output. For HTML responses, prefer
.ftlh so a future attribute-binding change can't introduce an XSS regression.
See Also:
- Since:
- 10.0.0
-
ClassDescriptionFlavor-neutral worker bean carrying the FreeMarker raw-template-dispatch logic shared by the
FreemarkerMixinmixin, theFreemarkerServletservlet, and theFreemarkerResourcechild flavors.Builder forFreemarkerDispatcher.Mixin that wires Apache FreeMarker view-rendering onto any Juneau REST resource.Builder forFreemarkerMixin.Request-scoped handle so FreeMarkerTemplateDirectiveModels can resolve per-request asset URLs duringtemplate.process.Child-resource flavor of theFreemarkerMixinmixin.Standalone servlet companion of theFreemarkerMixinmixin.Immutable value class returned from@RestOp-annotated methods to ask the framework to render an Apache FreeMarker template.Marker for an attribute value that promises to be adopted during the render (unwrapped from the data model by some directive and applied to render-scoped state), and wants the render to fail if that never happens instead of silently behaving as if the attribute was absent.ResponseProcessorthat detectsFreemarkerView-typed return values and asks the configuredConfigurationto render them directly onto the response writer.