java - using mustache templates with jersey -
i want integrate mustache-based templates bailiwick of jersey 2.
in pom.xml have:
<dependency> <groupid>org.glassfish.jersey.ext</groupid> <artifactid>jersey-mvc-mustache</artifactid> <version>2.9</version> </dependency>
my resource class looks this:
@path(value = "/appstatus") public class appstatuschecker { @template(name = "/index.mustache") @get public context getstatus() { homecoming new context(4); } public static class context { public integer value; public context(final integer value) { this.value = value; } } }
in web.xml have this:
<init-param> <param-name>jersey.config.server.mvc.templatebasepath.mustache</param-name> <param-value>/templates</param-value> </init-param>
and when app deployed, under web-inf/classes
have folder templates
index.mustache
inside. content is:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>simple mustache test</title> </head> <body> <h1>this mustacheee</h1> {{value}} </body> </html>
what see after calling myapp/appstatus url is: {"value":4}
expect html. there of import part of setup missing?
i had register provider like:
final resourceconfig rc = new resourceconfig().property( mustachemvcfeature.template_base_path, "templates" ).register( mustachemvcfeature.class ).packages("com.example"); homecoming grizzlyhttpserverfactory.createhttpserver(uri.create(base_uri), rc);
not sure if using grizzly. but, maybe help someone.
https://jersey.java.net/documentation/latest/mvc.html#mvc.registration
java template-engine mustache jersey-2.0
No comments:
Post a Comment