Question

I use the code at the bottom to programmatically configure my GrizzlyWebServer. I would now like to use the FreemarkerMvcFeature, which is suggested to be added like this:

new ResourceConfig().register(org.glassfish.jersey.server.mvc.freemarker.FreemarkerMvcFeature)

The Problem is, that the register method is only available in org.glassfish.jersey.server.ResourceConfig but the girzzly factory expects a com.sun.jersey.api.core.ResourceConfig. Is there a way to register features to a 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);
Was it helpful?

Solution

I think you somehow mixed up Jersey 1 and Jersey 2 dependencies. According to this https://jersey.java.net/apidocs/latest/jersey/org/glassfish/jersey/server/class-use/ResourceConfig.html#org.glassfish.jersey.grizzly2.httpserver

Jersey 2.0 GrizzlyHttpServerFactory accepts org.glassfish.jersey.server.ResourceConfig as a parameter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top