import akka.actor.ActorSystem; import akka.http.javadsl.Http; import akka.http.javadsl.server.Route; import akka.http.javadsl.server.AllDirectives; public class SimpleServer extends AllDirectives { public static void main(String[] args) { ActorSystem system = ActorSystem.create("simple-server"); final Http http = Http.get(system); Route route = path("hello", () -> get(() -> complete("Hello, World!") ) ); http.newServerAt("localhost", 8080) .bind(route) .handleAsync((binding, exception) -> { if (exception == null) { System.out.println("Server started at http://localhost:8080/"); } else { System.err.println("Failed to bind to localhost:8080: " + exception.getMessage()); system.terminate(); } return null; }); } }


上一篇:
下一篇:
切换中文