r/learnjava • • Dec 12 '20

[ASK] How to Learn Java Spring?

I have a background in backend development using Python Django, but now I have to use Java Spring. I can do programming in Java but haven't used Spring.

But the problem is there are so many Java Spring framework like Hibernate, Security, MVC, etc. In addition, I also see that we have to define our ORM implementation like how to make the SQL query, etc. I haven't done anything like that because in Python Django the ORM implementation has been made by the framework.

I would like to learn how to make a REST API as most of the backend job required this for Junior Engineer (Fresh Graduate), how do I start? do I need to learn all java spring framework?

78 Upvotes

46 comments sorted by

View all comments

-4

u/[deleted] Dec 12 '20

You don't need Spring, but since you mentioned that you have to, I would start with SpringBoot.

For ORM search for JPA, which is a way of interacting with the database. It's not part of Spring.

I avoid frameworks like the plague, but I understand they're helpful for people who are starting out to learn and who want to move to something more powerful afterwards.

4

u/[deleted] Dec 12 '20

I find this incredibly interesting, where do you work that you are able to "avoid frameworks" so aggressively?

2

u/[deleted] Dec 12 '20 edited Dec 12 '20

Cemex -> Novell -> IBM -> Amazon...

That's my history. Spring is less performant than EJBs for instance. We tested it when I was at IBM, it might have changed now but I don't see hard data to refute our previous findings.

https://github.com/luiz158/spring-vs-ejb-vs-cdi-benchmark

https://adam-bien.com/roller/abien/entry/high_performance_java_ee_from

At Amazon there's Coral where tou define the api and it generates the clients for you.

Spring is also not cloud optimized. Container images have a last layer which is in the hundreds of Megabytes, thus losing all benefits of image layer caching.

Regular wars can be in the hundreds of Kilobytes (3 orders of magnitude smaller than Spring) for the last layer and I can deploy 50 times per day and just send the last layer to the container regsitry, pipelines are faster, etc.

If you want to use something more powerful, you can start with microprofile.io and once you're ready, you can take your microprofile and put it in quarkus.io

If you're used to deploying jars, then most vendors provide a way to create uberjars like Spring does, but that feature is not popular anymore. Payara-micro does this.

1

u/nekokattt Dec 12 '20

WARs aren't exactly standalone like spring boot applications are, which are essentially fat jars usually. Spring Boot jars just contain EVERYTHING including the server backend, which enables you to freely toss the blob at a wider range of environments and have it "just work" without a preconfigured Java-level environment to run it in first. Other than that, Spring Boot MVC usually is using servlets under the hood anyway. Reactor/webflux is a different kettle of fish, ofc.

Spring alone doesnt make the JAR size that much bigger. You can easily write an OSGi-based spring application for an ESB such as JBoss Fuse and keep the full JAR under a few megabytes.

Of course, shared environments can be more painful as it is easier to descend into dependency hell, from experience.

1

u/[deleted] Dec 13 '20

Read again, I explicitly mentioned you can make an uberjar from a war just like SpringBoot.

1

u/nekokattt Dec 13 '20

I am aware, I was more pointing out that nothing is forcing you to do this with spring boot either, which kind of nullifies the size point somewhat

1

u/[deleted] Dec 13 '20

You will still have the problem of the last layer of the container image containing everything, and everytime you deploy, you send everything, even the things that haven't changed.

Spring is trying to solve it, but as I said, that will turn into thinwars in the end. If I'm going to use thinwars then I'd rather not depend on any external library, which would inevitably lower my performace by introducing a layer.

The uberjar is not needed because the container image has everything inside: the server, the services, etc. It takes the place of the uberjar, bit with added benefits like caching.

1

u/nekokattt Dec 13 '20

Why aren't you just keeping your common dependencies in a common layer? Unless you are constantly changing dependencies, surely that resolves this issue, right?

1

u/[deleted] Dec 13 '20

I think I haven't conveyed the problem properly. The problem is not from dependencies. The problem is Spring.

Here's how they're trying to solve it. It's a suboptimal solution since we can still get better performance, smaller images, and quicker deployments just by switching to EJBs.

https://spring.io/blog/2020/08/14/creating-efficient-docker-images-with-spring-boot-2-3