简体   繁体   中英

Convert Grizzly/Jersey to Payara

So, we've built a webapp using Grizzly/Jersey. You run the produced jar file, and it then provides REST endpoints, which allow pulling data from the database and creating new entries, etc. For one reason or another, we now want to migrate to a webserver, like Payara or Glassfish or something. I'm having trouble getting it to work. It compiles to a war, now, and gets deployed to Payara. Following Deploying jersey web services on Payara 4 doesn´t expose methods , I got it to at least acknowledge that there are endpoints. However, they rely on an injected EntityManager, which we define/bind (along with its dependencies) in a ResourceConfig subclass, which isn't getting loaded, so it crashes. Anybody know how to load the ResourceConfig? Also, anything else that will need to be done to get this working?

If you're going off the answer from your linked post

@javax.ws.rs.ApplicationPath("API_PATH_FOR_JAXRS")
public class SampleApplication extends Application {

}

This would explain the behavior you are seeing. An empty Application annotated with @ApplicationPath will cause the Jersey bootstrap to scan the classpath for @Path and @Provider class, and register those classes.

But you are using a ResourceConfig to do all your registration yourself. It just happens that ResourceConfig is actually a subclass of Application . So instead of creating a new Application subclass to put the @ApplicationPath annotation on, just put on your ResourceConfig subclass.

If you were not subclassing ResourceConfig previously, eg

ResourceConfig config = new ResourceConfig()
    .packages("...")
    .register(...);

Then just subclass it now

@ApplicationPath("...")
public class AppConfig extends ResourceConfig {
    public AppConfig() {
        packages("...");
        register(...);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM