Skip to content

Creating REST Application

Endi S. Dewata edited this page Sep 9, 2023 · 1 revision

To create a REST application, add the HttpServletDispatcher into the web.xml and specify the application class.

<servlet>
    <servlet-name>RESTEasy</servlet-name>
    <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
    <init-param>
        <param-name>javax.ws.rs.Application</param-name>
        <param-value>org.example.rest.RESTApplication</param-value>
    </init-param>
</servlet>

To enable the REST services they need to be registered in the application class.

public class RESTApplication extends Application {

    private Set<Object> singletons = new HashSet<Object>();
    private Set<Class<?>> classes = new HashSet<Class<?>>();

    public RESTApplication() {
        classes.add(AccountService.class);
        classes.add(UserService.class);
    }
}