java – GrizzlyServerFactory. The difference between createhttpserver and the new grizzly webserver
•
Java
I am using Jersey and embedded grizzly web server to create restful web services
I see two ways to create an embedded grizzly web server Who can tell me the difference between the two?
public static void main(String[] args) throws IOException,ConfigurationException,DBException,DaxException { GrizzlyWebServer gws = new GrizzlyWebServer(8085,"/var/www"); ServletAdapter jerseyAdapter = new ServletAdapter(); jerseyAdapter.addInitParameter( PackagesResourceConfig.PROPERTY_PACKAGES,"com.merchant.services"); jerseyAdapter.setServletInstance(new ServletContainer()); gws.addGrizzlyAdapter(jerseyAdapter,new String[]{"/"}); // let Grizzly run gws.start(); }
The second way is:
ResourceConfig rc = new PackagesResourceConfig("com.merchant.services"); HttpServer httpServer = GrizzlyServerFactory.createHttpServer(BASE_URI,rc); httpServer.start();
The first way is that it is easy to configure the web server
Solution
one
The grizzly web service using the servletadapter method supports jax-rs, servlets and filters Wich offers you,
Jersey servletcontainer
This will give you enough flexibility to provide more complex configurations
two
If you think servletcontainer is an additional dependency, use the second one This is,
Jersey simple HTTP server
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码