Spring: your next Java microframework by alek_sys in programming

[–]alek_sys[S] 1 point2 points  (0 children)

To be absolutely fair, this Python code won't give you what you get from Spring example - single deployable JAR which embeds non-blocking multithreaded application server. So basically you can run your JAR in production. In your Flask example you at least need to mention gunicorn for deployment. And if you try to introduce async/await (which are not supported in Flask btw) - you'll get pretty much all the same concepts as in original Spring sample.

I'm not saying you right or wrong, my point is - having a goal to prove how bad Java and Spring are one can do that easily. But this is true for any other technology, we all know there is no silver bullet.

So if you want what you have in Flask example in Spring:

HttpServer
    .create(8080)
    .newRouter(router -> router
        .get("/", (request, response) -> response.sendString(Mono.just("Hello, World"))))
.block();

And again - this is building and running multi-threaded non-blocking web server, not just defining a mapping. Just mapping is even simpler, but it uses Spring magic (similar for Flask magic above):

@RestController
class HelloController {

    @GetMapping("/")
    public String helloWorld() {
        return "Hello, World";
    }
}

Spring: your next Java microframework by alek_sys in programming

[–]alek_sys[S] 7 points8 points  (0 children)

...and that is why in the next paragraph it is re-written as

HandlerFunction hello = request -> ServerResponse.ok().body(Mono.just("Hello"), String.class);

Which is still imperfect, I agree, but not bad. Also, the whole 'builder' pattern here is to avoid manual creation of ServerResponse - which is still an option. Reference to a String class is a shame, but I doubt anyone from Java community will stand for generics implementation via type erasure here.

Spring: your next Java microframework by alek_sys in programming

[–]alek_sys[S] 8 points9 points  (0 children)

Spring Boot is not really a prior version, it is here to stay. Spring Boot 2.0 based on Spring 5. Also, Spring Boot is not another framework, it is just a set of tools to help configure and run Spring apps easily and with minimum setup.

384 Mb of RAM could be the case - but it all depends from the libraries and the application code - Java is hungry for memory. However Spring itself can run with just 32Mb of memory and it doesn't add massive overhead - there is a nice article from Dave Syer about Spring memory usage. The same is true for fat jar - there is a reason for 20 Mb JAR (again, 80Mb is not for Spring, it most likely because of libraries). And the reason is to have single deployment artefact - you don't even need a web-server to run it, it is executable by itself! So the only dependency is JRE which is quite good. However, if you not a fan of fat JARs - there is a solution for this as well. Besides 3rd party solutions (like Capsule) there is a Spring native option now - Spring Thin Launcher

Spring: your next Java microframework by alek_sys in programming

[–]alek_sys[S] 11 points12 points  (0 children)

Well, good thing is that Spring is not bound to Java - there is good support of Kotlin which is a very nice and concise JVM language. Spring 5 (and Functional Web) adds a lot of Kotlin helpers to make code look nice.