我使用底部的代码以编程方式配置我的GrizzlyWebServer。我现在想使用FreemarkerMvcFeature,建议添加如下:
new ResourceConfig().register(org.glassfish.jersey.server.mvc.freemarker.FreemarkerMvcFeature)
问题是,寄存器方法仅在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);
答案 0 :(得分:2)
我认为你以某种方式混淆了泽西1和泽西2的依赖。 根据这个 https://jersey.java.net/apidocs/latest/jersey/org/glassfish/jersey/server/class-use/ResourceConfig.html#org.glassfish.jersey.grizzly2.httpserver
Jersey 2.0 GrizzlyHttpServerFactory接受org.glassfish.jersey.server.ResourceConfig作为参数。