我使用底部的代码以编程方式配置我的 GrizzlyWebServer。我现在想使用 FreemarkerMvcFeature,建议像这样添加:
new ResourceConfig().register(org.glassfish.jersey.server.mvc.freemarker.FreemarkerMvcFeature)
问题是, register 方法仅适用于org.glassfish.jersey.server.ResourceConfig
但 girzzly 工厂需要一个com.sun.jersey.api.core.ResourceConfig
. 有没有办法将功能注册到com.sun.jersey.api.core.ResourceConfig
?
// include all resource classes in package somepackage
ResourceConfig rc = new PackagesResourceConfig("somepackage");
// configure server to use Freemarker template engine
Map<String, Object> params = new HashMap<String, Object>();
params.put(FreemarkerViewProcessor.FREEMARKER_TEMPLATES_BASE_PATH, "/src/main/resources/templates");
rc.setPropertiesAndFeatures(params);
// create the server with the resource config
HttpServer server = GrizzlyServerFactory.createHttpServer(BASE_URI, rc);