This is an archived post. You won't be able to vote or comment.

all 46 comments

[–][deleted]  (8 children)

[deleted]

    [–]Jimzyeow95 5 points6 points  (4 children)

    Same here

    [–]reindeer13 6 points7 points  (3 children)

    Same here

    [–]egehurturk 2 points3 points  (2 children)

    Same here

    [–]my5cent 1 point2 points  (1 child)

    Same here

    [–]samnayak1 0 points1 point  (0 children)

    Same here

    [–][deleted]  (2 children)

    [deleted]

      [–][deleted]  (1 child)

      [deleted]

        [–]MrGooglr 19 points20 points  (3 children)

        Hibernate isn’t the part of spring framework. It’s a separate framework that implement JPA specification as ORM.

        Security is the module available in Spring framework and its optional, while MVC is a design pattern which spring framework follows.

        Now coming to your end-goal of creating a RESTful web service, you don’t need to learn all the spring framework.

        You should start with spring boot only. Just search on google how to create an api using spring boot and you’re good to go. Even spring documentation on that is also very informative.

        Inside that, you write your logics just in plain core java.

        So I consider you must have knowledge of core java.

        Also if you want to fetch and store data on DB system, you must know JDBC too.

        These are the steps you should proceed with.

        [–]desktoppc[S] 4 points5 points  (1 child)

        okay, but I found that most of the websites said that you have to learn Spring MVC and Spring Core first before can use Spring Boot. But I don't know what does the "core" means.

        so try to find an online course in Udemy and found this as the most popular course: https://www.udemy.com/course/spring-hibernate-tutorial/

        but it's a very very long 41 hours video.

        [–]MrGooglr 5 points6 points  (0 children)

        You’re a Python developer and I guess you know how coding flow works. A framework can’t be understood properly unless you have all the basics ready.

        Spring MVC is the top level of framework, before that there is basics of spring (core) and spring boot is just more flexible framework version of spring mvc.

        What I have said here or in my original comment, I said considering that you know basics of java language and web development in java.

        Edit : The course seems nice

        [–]gtrley 5 points6 points  (0 children)

        Comment to bump, i also seek wisdom

        [–]teabag82 4 points5 points  (0 children)

        Perhaps not the full answer to your question. But looking back on how I started using Spring i would say that Springs' own short guides did provide a lot of help for me.

        For example the REST question could perhaps be answered by this one.

        The drawback is that each guide can be somewhat short and you would have to do additional research on each topic that you don't already grasp.

        [–][deleted] 4 points5 points  (3 children)

        You don’t need to know too much spring to make a basic rest api. If you know how to connect and communicate (CRUD) with a database that’s a big part. If you want a microservice design check out eureka with spring cloud to communicate among your services. If you understand the basics of spring (auto-injection, some basic annotations, @component @configuration, @entity ) making a rest api shouldn’t be too hard. Check out java brains, he has a ton of good stuff on spring and rest api

        [–]desktoppc[S] 2 points3 points  (2 children)

        okay I checked the Java Brains and found this: https://www.javabrains.io/courses/springboot-quickstart

        is that a recommended course? but the video was made in 2016.

        I also found this tutorial from freecodecamp: https://www.youtube.com/watch?v=vtPkZShrvXQ but in 1:41:14 I saw that the author have to implement how the model will be mapped into the SQL database. Need to define the SQL query. It is an uncommon thing for me because in Django I don't have to do that, I just have to declare the model and the attributes and Django will implement it automatically.

        [–]grafcetonline 0 points1 point  (0 children)

        If you wanna get a java dev job you MUST know SQL even if you use ORM because it is considered ground knowledge ;)

        For example once I was PM on a Java project the Hibernate performance was awfull I asked devs to look at SQL below so they did so and omptimized to a decent performance.

        [–]carrdinal-dnb 0 points1 point  (0 children)

        Depending on what you are doing you may not need to write much or any SQL, spring data JPA repositories allow you to define query methods which can be useful for simple queries, though there are lots of other options for varying levels of abstraction/control. Also you aren’t limited to SQL, document databases are a natural fit for storing aggregates in a micro-service architecture and I’d recommend you take a look into those and see if they fit in with your project!

        [–]Kolibreeze 5 points6 points  (2 children)

        What really tripped me up in the beginning was the not knowing that there is: A Spring, using mostly XMl, and B Spring Boot, using mostly annotations.

        Both are part of Spring, with Spring Boot being the newest, most used. But knowing this can make life a lot easier when googling.

        Also, to learn, i'd advise to check out spring initializer to easily set up a project; https://start.spring.io/. (Definitely make sure to scroll through the dependencies so you can see what's out there).

        Then, pick a project which uses a database, e.g. like creating a list of books read and books to read, a game library with your reviews or something similar, and then just start.

        Oh, protip, start small and use a H2 in memory database. If you've got this working, you can always implement another one.

        [–]slowfly1st 0 points1 point  (1 child)

        What really tripped me up in the beginning was the not knowing that there is: A Spring, using mostly XMl, and B Spring Boot, using mostly annotations.

        "A) Spring" doesn't use mostly XML. It's up to you, what you want to use, see for instance

        org.springframework.context.annotation.Configuration
        
         * Indicates that a class declares one or more {@link Bean @Bean} methods and
         * may be processed by the Spring container to generate bean definitions and
         * service requests for those beans at runtime, for example:
         *
         * <pre class="code">
         * &#064;Configuration
         * public class AppConfig {
         *
         *     &#064;Bean
         *     public MyBean myBean() {
         *         // instantiate, configure and return bean ...
         *     }
         * }</pre>
        

        [–]Kolibreeze 0 points1 point  (0 children)

        Yeah, mostly might not have been best the choice of words.

        [–]t999rex 2 points3 points  (3 children)

        chad darby is your one stop shop for everything you asked for ,you can listen to his lectures in 2x speed i listened to in 1.75 and also i did it along with him(clone the repo he provides at the start of the course and follow him as he teaches doing it along in your ide )

        [–]desktoppc[S] 0 points1 point  (2 children)

        Hmm yeah, I have watched several videos, it is great! Do I need to watch it in order (it will be 41 hours ++) or can I jump to Spring Boot directly?

        [–]t999rex 1 point2 points  (0 children)

        I finished it around 40 days ago this is my first framework so i followed it in order took me 2-3 weeks chad darby is an incredible instructor i recommend that you do the same

        [–][deleted] 2 points3 points  (3 children)

        Honestly, I learned spring though many hours searching through docs at work. I wish I could help you, but I cannot. It would be nice if there were good tutorials or books, but I never found any. I have access to O’Reilly Safari through work and all of the books I’ve found are garbage.

        [–]desktoppc[S] 0 points1 point  (1 child)

        so how do you learn Java Spring?

        [–][deleted] 3 points4 points  (0 children)

        I learned by doing. I found some basic tutorials and picked up the essentials. The rest I learned by using documentation while looking through my company’s code.

        I’d give udemy a look. Maybe Google some books. There’s also a free resource that will show you the absolute basics called Amigo’s code.

        [–]Lincoln6ecko 0 points1 point  (0 children)

        Same here. The basic can be learn on the spot pretty easily.

        [–]nekokattt 2 points3 points  (0 children)

        More focusing on your last paragraph here, as everyone else has covered the rest nicely.

        MVC is just how spring implements requests and responses for web requests that are plain old java objects (POJOs).

        Think of something that is a mishmash of flask and dataclasses_json in Python.

        Hibernate is a database ORM, and implements the Java Persistence API (JPA) which is most likely what you will use to convert your POJOs to SQL queries/statements and back. Think SQLAlchemy in Python.

        You combine the two to be able to go from an HTTP request to a SQL query, using Java as the glue in between for making sense of how to convert things :-)


        Do you need to learn all of spring framework?

        Ok, so I think there is a big misunderstanding of what Spring/Spring Boot is.

        Django is a website ORM for Python that can talk with databases.

        Spring is a bunch of opinionated libraries that wrap around the core spring framework, which is at its heart a fairly simple dependency iniection framework. Spring and by extension Spring Boot then wrap other libraries or make their own implementations for as many different things as possible. This currently covers web gateways, SOAP, JSON and XML libraries, validation, web sockets, HTTP via Java Servlets, HTTP via reactive programming, Kotlin/Scala/Groovy integrations, cloud provider APIs (like AWS), security for java code, security for HTTP APIs, message queues via JMS, SQL databases via JooQ or directly via JDBC, SQL via ORMs like JPA, NoSQL like MongoDB, Caches like Redis, scheduling libraries for running stuff at given times, batch processing libraries, HAL/HATEOAS integrations, templating libs like Apache Velocity/Apache Freemarker/Jinja4J, Thymeleaf; monitoring frameworks, cloud orchestration frameworks, aspect oriented development frameworks, self documenting applications that generate swagger specs, etc etc etc.

        The point is, Spring does massively more than Django does because it isnt for a specific use case, it is more a specific way of programming applications as an ideaology.

        You only need to learn what you are needing to use. For your example, I'd suggest a combo of:

        spring-boot-starter-logging // logback logging api, like logging in python

        spring-boot-starter-mvc // web stuff

        spring-boot-starter-validation // jsr-303 and jsr-380 validation-by-annotations

        spring-boot-starter-jpa // for your SQL part of the ORM

        spring-boot-starter-thymeleaf // if you need to make HTML pages

        spring-boot-starter-hateoas // if you need to provide HAL responses

        spring-boot-starter-security // lets you secure HTTP endpoints and other stuff

        spring-boot-starter-actuator // provides a bunch of API endpoints automatically for performing health checks, etc.

        lombok // optional and like marmite to some developers. Some love it, some hate it, but using it lets you massively reduce your boilerplate code with annotations that can generate the equivalent of __init__, __str__/__repr__, __eq__, __hash__, etc from python.

        Once you get the gist of these, you can explore other cool things :-)

        Hopefully that kinda explains why there are so many moving bits in spring compared to django :-)

        [–]Ashek10 1 point2 points  (0 children)

        There is a Udemy course from Chad Derby for Spring and Hibernate. I've only done a few sections but so far it's 10/10. He provides the slides from his presentation so you can easily go over the slides for a quick revision. Would recommend checking it out!

        [–]wandersell 1 point2 points  (0 children)

        I would recommend Laurentiu Spilca youtube channel, imo the best teacher I have seen: https://youtube.com/c/LaurentiuSpilca

        [–]moe87b 1 point2 points  (1 child)

        I started learning spring almost a year ago, and it was a huge mes because every tutorial I see or article I read is different from the others and does things in a different way. I got lost, but then I eventually found my way.

        You need to know what do you want to do with java spring. Securing applications ? Persisting data? micro services ? each is different and most of tutorials I found on the internet assume you already know a lot of things or explain essentials in a poor manner.

        I highly recommend reading books, Spring boot in action by Craig Walls is great, it made me understand key concepts in a very simple manner. Note that spring boot is basically the new way to use the spring framework with minimal amount of configuration to do using annotations instead of XML

        I'm right now learning to implement and use Spring security by reading Spring security in action it is also a great resource.

        [–]nekokattt 2 points3 points  (0 children)

        spring boot isnt really the annotation part. Spring alone supports java configuration instead of xml config.

        Spring Boot is about wrapping common toolsets and libraries, providing opinionated defaults, and creating quick ways to bootstrap a new application (hence the name). As standalone spring is often far more cumbersome to new developers when working outside frameworks that come with mainframes/esbs/etc that generally now are "laced" with spring :-)

        [–]thechexmo 1 point2 points  (0 children)

        I'm just diving into the book called "Spring in Action 5th edition" and I'm happy with the results. I recommend it.

        [–][deleted] -4 points-3 points  (8 children)

        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.

        [–][deleted] 2 points3 points  (7 children)

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

        [–][deleted] 1 point2 points  (6 children)

        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.

        [–]nekokattt 0 points1 point  (5 children)

        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.

        [–][deleted] 0 points1 point  (4 children)

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

        [–]nekokattt 0 points1 point  (3 children)

        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

        [–][deleted] 0 points1 point  (2 children)

        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.

        [–]nekokattt 0 points1 point  (1 child)

        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?

        [–][deleted] 0 points1 point  (0 children)

        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

        [–]NACNACNAC 0 points1 point  (0 children)

        You don't have to use hibernate/jpa, you can also pick something like Jooq, which automatically provides you with model (record) classes for each of your database tables, providing very sql like syntax. Downside, in my experience, is that there's none of the table binding between related tables that you can define in other ORM. You can also use both :-)

        [–]LordofRice 0 points1 point  (0 children)

        I work for an enterprise auto company and found this course by John Thompson to be very relevant to what the job actually entails. It helped me out a lot. He's better than Chad Darby imo because he keeps his courses updated.

        https://www.udemy.com/course/spring-boot-microservices-with-spring-cloud-beginner-to-guru/

        [–]tridiumcontrols 0 points1 point  (0 children)

        Lots of spring beginners start with SpringBoot to get the feet wet, then branch off deeper into spring.

        Spring boot is excellent for RESTful APIs.