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


package org.apache.juneau.rest.server.view.mustache
Mustache view-rendering bridge — opt-in juneau-rest-server-view-mustache module.

Provides three sibling pieces that together let a Juneau REST resource render Mustache templates via mustache.java:

  • MustacheMixin — mixin that renders raw Mustache templates from the importer's classpath under /mustache/* and auto-registers MustacheViewRenderer.
  • MustacheView — immutable value class (implements the core View interface) returned from @RestOp methods to ask the framework to render a Mustache template.
  • MustacheViewRenderer — ResponseProcessor that detects MustacheView returns and dispatches them to the configured MustacheFactory via factory.compile(templateName).execute(writer, scope).
Composition example (microservice):

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

Engine-agnostic packaging:

The bridge module's main POM declares only com.github.spullara.mustache.java:compiler in provided scope — no concrete Mustache transitive dep ships here. Consumers add the engine matching their deployment:

  • Juneau microservice / Jetty / Spring Boot: add com.github.spullara.mustache.java:compiler. With no user-supplied factory bean, the bridge builds a default MustacheFactory on first request anchored on the importer's classpath under the configured base path.
  • Custom: register your own @Bean MustacheFactory with whatever resolvers, object handlers, and encoders you need.

When no Mustache engine is on the classpath, the renderer surfaces a clear diagnostic naming the missing dependency and linking to the "Choosing a MustacheFactory" matrix in MustacheViewSupport.md.

Note on Spring Boot's mustache starter:

Spring Boot's spring-boot-starter-mustache pulls in com.samskivert:jmustache (a separate Mustache implementation), not mustache.java. The bridge is mustache.java- specific; consumers who want to use jmustache instead supply their own ResponseProcessor rather than MustacheViewRenderer.

See Also:
Since:
10.0.0