Search

Chapter 31. Embedded Container

download PDF
RESTEasy JAX-RS comes with an embeddable server that can be run from your classpath. It packages the TJWS (Tiny Java Web Server) embeddable Servlet container with JAX-RS.
From the distribution, move the JARs in resteasy-jaxrs.war/WEB-INF/lib into your classpath. You must register your JAX-RS beans programmatically using the embedded server's Registry. Here's an example:

@Path("/")
public class MyResource {

   @GET
   public String get() { return "hello world"; }
 

   public static void main(String[] args) throws Exception 
   {
      TJWSEmbeddedJaxrsServer tjws = new TJWSEmbeddedJaxrsServer();
      tjws.setPort(8081);
      tjws.getRegistry().addPerRequestResource(MyResource.class);
      tjws.start();
   }
}

The server can either host non-encrypted or SSL-based resources, but not both. See the Java Documentation for TJWSEmbeddedJaxrsServer and its superclass TJWSServletServer for further information. The TJWS website is also very informative.
To use Spring, you will need the SpringBeanProcessor. Here is a pseudo-code example:

   public static void main(String[] args) throws Exception 
   {
      final TJWSEmbeddedJaxrsServer tjws = new TJWSEmbeddedJaxrsServer();
      tjws.setPort(8081);

      org.resteasy.plugins.server.servlet.SpringBeanProcessor processor = new SpringBeanProcessor(tjws.getRegistry(), tjws.getFactory();
      ConfigurableBeanFactory factory = new XmlBeanFactory(...);
      factory.addBeanPostProcessor(processor);

      tjws.start();
   }

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.