0

I have an old application with Spring MVC on Tomcat in which I want to start a server on a different port.

I usually use the handy Javalin for such cases. But in this case it doesn't suit me because it is loaded using Jetty which loads javax.servlet-api 3.1, but the application uses javax.servlet-api 3.0.

Can anyone suggest a similar Framework or a convenient pattern for HttpServer (so as not to create a Handler for each request).

An example of creating a server in Javalin:

public MyServer() {
    Javalin app = Javalin.create (). Start (7000);
    app.get ("/", ctx -> ctx.result ("Hello World"));
    }
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
SnejOK
  • 75
  • 7
  • 1
    Servlet 3.1 is upwardly compatible with any Servlet 3.0 code. What exactly concerns you about running your Servlet 3.0 app within a Servlet 3.1 container? – Basil Bourque Oct 29 '21 at 22:48
  • 1
    FYI, for discussion of changes between Servlet 3.0 & 3.1, see these two posts at IBM.com: [behavior changes](https://www.ibm.com/docs/en/was-liberty/core?topic=31-servlet-behavior-changes) and [features](https://www.ibm.com/docs/en/was-liberty/core?topic=31-servlet-feature-functions). – Basil Bourque Oct 30 '21 at 00:16
  • 2
    [Java 18](https://en.wikipedia.org/wiki/Java_version_history#Java_18) brings a built-in simple web server. See [*JEP 408: Simple Web Server*](https://openjdk.java.net/jeps/408). Early access [available now](https://jdk.java.net/18/). I have no idea if that meets your needs or not. And this web server is *not* meant to be used in production in any serious manner: “It is not a goal to provide a feature-rich or commercial-grade server. Far better alternatives exist…” – Basil Bourque Oct 30 '21 at 00:18
  • @BasilBourque Basically, the problem is that we have several servers for different regions with different gradle configurations. And that can be a lot. – SnejOK Oct 30 '21 at 00:30
  • @BasilBourque But the articles you gave me are very helpful, thanks! – SnejOK Oct 30 '21 at 00:32
  • 2
    You might want to read about not having different build environments for different servers or regions on https://12factor.net – OneCricketeer Dec 17 '21 at 15:04

1 Answers1

0

You can use Vert.x

HttpServer server = Vertx.vertx().createHttpServer();
server.requestHandler(new Handler<HttpServerRequest>() {
  public void handle(HttpServerRequest request) {
    request.response.end("Hello Vert.x");
  }
});
System.out.println("server is running on http://localhost:9090/");
server.listen(9090);
Asad Awadia
  • 1,417
  • 2
  • 9
  • 15