Package org.apache.juneau.rest.server.view.freemarker


package org.apache.juneau.rest.server.view.freemarker
Apache FreeMarker view-rendering bridge — opt-in juneau-rest-server-view-freemarker module.

Provides three sibling pieces that together let a Juneau REST resource render Apache FreeMarker templates:

Composition example (microservice):

@Rest(path="/app", mixins=FreemarkerMixin.class) public class AppResource extends RestServlet { @Bean FreemarkerMixin freemarker() { return FreemarkerMixin.create() .basePath("/templates/") .templateSuffix(".ftlh") .build(); } @RestGet("/hello/{name}") public View hello(@Path String name) { return FreemarkerView.of("hello").attr("name", name); } }

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 default Configuration on first request anchored on the importer's classpath under the configured base path.
  • Spring Boot: add spring-boot-starter-freemarker. Spring Boot autoconfigures a freemarker.template.Configuration bean which the bridge picks up automatically via BeanStore.getBean(Configuration.class) — no further wiring required.
  • Custom: register your own @Bean freemarker.template.Configuration with 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