1

我使用底部的代码以编程方式配置我的 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);
4

1 回答 1

2

我认为您以某种方式混淆了 Jersey 1 和 Jersey 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 作为参数。

于 2013-07-01T19:14:07.213 回答