I use RestEasy with embedded Tomcat to export runnable jar file which deploy some Rest API (just for testing, I don't want to use SpringBoots). I've write some code in main entry point to register HttpServletDispatcher
public class Main {
public static void main(String[] args) throws Exception {
try {
new Main().run();
} catch (Throwable t) {
t.printStackTrace();
}
}
public void run() throws Exception {
Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
Context ctx = tomcat.addContext("/", new File(".").getAbsolutePath());
String contextPath = "/";
String appBase = ".";
tomcat.getHost().setAppBase(appBase);
tomcat.addWebapp(contextPath, appBase);
Tomcat.addServlet(ctx, "rest-easy-servlet", new HttpServletDispatcher());
ctx.addServletMapping("/*", "rest-easy-servlet");
tomcat.start();
tomcat.getServer().await();
}
}
Server starts successfully but without any Rest API. When access to the path localhost:8080/users/hello I've got error in log.
Nov 09, 2017 2:21:22 PM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler ["http-nio-8080"] Nov 09, 2017 2:21:30 PM org.jboss.resteasy.core.ExceptionHandler SEVERE: failed to execute javax.ws.rs.NotFoundException: Could not find resource for full path: http://localhost:8080/users/hello at org.jboss.resteasy.core.registry.ClassNode.match(ClassNode.java:73) at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48) at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:444) at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:234) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:171) at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)
I think RestEasy don't have any signal to scan its components. Please help me the way to scan RestEasy components, or the way to register RestEasy same as using web.xml