5 Common Mistakes Spring Developers Make

Sdílet
Vložit
  • čas přidán 11. 07. 2024
  • In this tutorial we will look at 5 common mistakes we make as Spring Developers and how we can improve on them. This isn't in any specific order but just 5 mistakes that I notice often when looking at the code of Spring Boot applications.
    🔗Resources & Links mentioned in this video:
    GitHub Repo: github.com/danvega/spring-com...
    👋🏻Connect with me:
    Website: www.danvega.dev
    Twitter: / therealdanvega
    Github: github.com/danvega
    LinkedIn: / danvega
    Newsletter: www.danvega.dev/newsletter
    SUBSCRIBE TO MY CHANNEL: bit.ly/2re4GH0 ❤️
  • Věda a technologie

Komentáře • 106

  • @d2k2
    @d2k2 Před 4 měsíci +22

    thanks! writing interfaces, which are never used are waste of time. good to hear this from an experienced spring developer.

    • @FrankAn-io7bz
      @FrankAn-io7bz Před 14 dny

      But using interfaces also hides the implementation details, right? The caller can use the functionality without caring about the details.

  • @tysonlawrie
    @tysonlawrie Před 16 dny +2

    This was great. #2 and #3 are what was drilled into years ago and ive never questioned them.

  • @hirokiminami4194
    @hirokiminami4194 Před 4 měsíci +4

    0:00 Intro
    1:27 Making everything public
    4:48 Field dependency injection
    7:19 Interface when it’s not needed
    10:33 Improper REST API design
    13:40 Improper exception handling

  • @kassemjenkins
    @kassemjenkins Před 4 měsíci +9

    Please continue along these line of topics!

  • @petritoivari
    @petritoivari Před 4 měsíci +6

    Can't wait for exception handling video. It has has always been bit of a mystery to me :) Or more like what is the proper way of doing it.

  • @darkogrozdanovski
    @darkogrozdanovski Před 4 měsíci +10

    It would be amazing to see something similar for spring data jpa

    • @JitterTed
      @JitterTed Před 4 měsíci +1

      I think using JPA when you don't need the complexity is a mistake. 😄

  • @VerhoevenSimon
    @VerhoevenSimon Před 4 měsíci +4

    Thank you for the interesting video, and number 6: not dropping by the Spring office hours.

    • @DanVega
      @DanVega  Před 4 měsíci +1

      Ohh that’s a good one haha 😂

  • @koladeam
    @koladeam Před 4 měsíci +1

    as always, thanks for this Dan! You're helping beginners like me in a massive way.

  • @simulbista8846
    @simulbista8846 Před 4 měsíci +1

    Thank you Dan. Very insightful.

  • @chaitanyashetty6745
    @chaitanyashetty6745 Před 4 měsíci +3

    Amazing Tutorial Dan! As someone who is exploring Spring, this was a great learning

  • @tobyzieglerrr
    @tobyzieglerrr Před 4 měsíci

    Very good basic points made here. Clear and concise. Dan delivers 😊

  • @nasserabbassi7303
    @nasserabbassi7303 Před 3 dny

    thank you first all, it worth also to mention that using controllerAdvice we can handle the exceptions also much better in spring

  • @ambarishkapil8004
    @ambarishkapil8004 Před měsícem

    Thanks for creating this video Dan. Looking forward to more additions on the common mistakes series. Cheers!

  • @pacifiquemunzihirwa7054
    @pacifiquemunzihirwa7054 Před 4 měsíci +16

    Pretty good video.
    I am a pretty stubborn developper and I don't usually implement things that do not improve that much on my coding time or make my code easier to understand.
    I am with you for theses 3 :
    - REST API recommendations should be followed.
    - Using constructor based dependency injection is BAE
    - Custom exceptions should always be implemented. I usually use a Controller Advisor to map my exceptions to Http Responses so that i can still you the Java exceptions and then transform the message into the body of a 4xx error code depending on the exception.
    - Using interfaces when you really need them (50/50) -> if you are doing more than CRUD transactions interfaces are a good way to show what methods you have implemented instead of reading all the code to find out.
    Not really with you on this:
    - For the way to structure your code (you should chose package by layer or package by feature depending on the project)

    • @jmrah
      @jmrah Před 4 měsíci

      I'll engage with you. Could you elaborate on your using interfaces point? What's the problem that an interface solves in your example? And why do you disagree with package by layer or package by feature? Do you usually organize your code another way?

  • @donaldf.coffin8130
    @donaldf.coffin8130 Před 4 měsíci +2

    Dan, thanks for sharing. I hope you will make this a series and add more "mistakes" to the repository and CZcams

  • @anoopktla
    @anoopktla Před 4 měsíci +3

    #1 is going to be problematic in the long run IMO. Agree with you about all others!

  • @fene2899
    @fene2899 Před 4 měsíci

    You're right. I've never made a mistake, but now if I do, I'll check back here for help. Thanks man. You put out consistently helpful tech content. I recently inherited a Spring project and I have a lot to learn.

  • @jacks808
    @jacks808 Před 4 měsíci +1

    Very good advice for a novice like me. Thanks a lot!

  • @TonInter
    @TonInter Před 4 měsíci

    Great video, thanks Dan! Looking forward to the exception video!

  • @user-ql1rg9mj9d
    @user-ql1rg9mj9d Před 4 měsíci +1

    good topic and easy explanation

  • @Alexander-vov
    @Alexander-vov Před 4 měsíci

    Thanks for good examples

  • @omaradrian80
    @omaradrian80 Před 4 měsíci

    Keep sharing good practices about coding with Spring.

  • @JimShingler
    @JimShingler Před 26 dny

    This is great, ... Keep them coming

  • @antonslonkin
    @antonslonkin Před 4 měsíci

    thanks!!! please continue!!!

  • @ficamu2
    @ficamu2 Před 4 měsíci

    Very useful content!
    Thanks!!

  • @isurucumaranathunga
    @isurucumaranathunga Před 4 měsíci

    learned a lot, thanks Dan

  • @marcincylkowski3004
    @marcincylkowski3004 Před 4 měsíci +1

    of course, it is sounds like very good series

  • @ikennashonowo9250
    @ikennashonowo9250 Před 4 měsíci

    Kindly continue this series.

  • @Uttkarsh_8
    @Uttkarsh_8 Před 4 měsíci

    Great content!!

  • @haroldpepete
    @haroldpepete Před 4 měsíci +1

    very useful, i think some of those mistakes are more general and not just to spring, be restful, excepcion hanlder, and everything is public is more about encapsulation in object oriented

  • @Skiamakhos
    @Skiamakhos Před 4 měsíci

    I've been guilty of most of these because that's how I learned from other developers to do it. You've given me some fuel for thought - thanks Dan!

    • @DanVega
      @DanVega  Před 4 měsíci +1

      I have done the same by just copying what others do without asking why they did it.

  • @sadiulhakim7814
    @sadiulhakim7814 Před měsícem

    Learned some good stuff

  • @alandosman5002
    @alandosman5002 Před 4 měsíci

    I really love the functional way to throw errors, we at our company we use a functional way to do Try and catch, which makes it readable and clean, we also dont throw an error if its needed by the user, we use a type Either and then return to left part which we defined an error with msg etc... we use Vavr for handling things with FP

  • @user-xb1pu1tj7e
    @user-xb1pu1tj7e Před 2 dny

    great content thank u

  • @FrankAn-io7bz
    @FrankAn-io7bz Před 14 dny

    #3 I always thought it was right to use interfaces, but there's nothing right or wrong with that, personal habits? I agree with your point. Using interfaces without multiple implementations wastes time.

    • @FrankAn-io7bz
      @FrankAn-io7bz Před 14 dny

      But using interfaces also hides the implementation details, right? The caller can use the functionality without caring about the details.

  • @finncrisp9900
    @finncrisp9900 Před 4 měsíci

    Looking forward to a video about @Transactional annotation and common mistakes while using it.

  • @adamm4739
    @adamm4739 Před 4 měsíci

    Actually none of them are mistakes. I would call them tips and they are great. Thanks!

  • @ismailforeveryone6889
    @ismailforeveryone6889 Před 4 měsíci +1

    please we need more

  • @ravimangalagiri
    @ravimangalagiri Před 4 měsíci +1

    Thanks!

    • @DanVega
      @DanVega  Před 4 měsíci

      Wow thank you so much for your generosity. I appreciate you 🤩

    • @ravimangalagiri
      @ravimangalagiri Před 4 měsíci

      @@DanVega np. what intellij theme did you use for the demo?

  • @Vityoube
    @Vityoube Před 4 měsíci

    What so interesting in case of mistake 3 Intellij in case of lone class implementation with only one method will suggest to make an interface from it :) This is the example, that actually not all the time IDE is suggesting the right thing :)

  • @HandledToaster2
    @HandledToaster2 Před 4 měsíci +2

    A previous tech lead I had disagrees on the useless-interface mistake. They believe it's good pattern to ALWAYS have an interface and an impl for everything. I don't see any value on that if there's never going to be alternative implementations.

  • @kyleryxn
    @kyleryxn Před 4 měsíci

    i love the feature package organization idea, can you make a video on it?

  • @ewoks42
    @ewoks42 Před měsícem

    Great tips @DanVega regarding handling errors video you mentioned at 13:40, is that one already published? tnx

  • @eyasuemana6946
    @eyasuemana6946 Před 4 měsíci

    love it

  • @jopadjr
    @jopadjr Před 3 měsíci

    Hi Dan, I recently came across an article highlighting Java vulnerabilities. In light of this, I believe it would be beneficial to create a playlist outlining the steps for: (1) Upgrading to the latest version of Java (2) Updating JAR files (3) Transitioning to the most recent dependencies. This playlist would serve as a valuable resource for us, subscribers, to proactively address potential security risks associated with outdated Java environments. Would you be available to create such a playlist? Thanks in advance.

  • @Jedimaster36091
    @Jedimaster36091 Před 3 měsíci

    My opinion is that it is wrong for the TodoFiveRepository to throw an exception (even a custom one), but instead, return an Optional. Reason being that it is not the repository's responsibility to determine whether this is an exceptional case or an expected scenario. Instead, it is the caller of the repository (direct or indirect) to figure out that, depending upon the scenario. Exceptions are to be used for exceptional cases, not for expected functional behavior. The repository should only throw an exception when there's a problem accessing the database.

  • @manjosh1990
    @manjosh1990 Před 4 měsíci

    thanks, now I know my mistakes :D
    In my org I also see a lot of circular dependencies, all done through field autowiring. Could you explain if it is the correct way? should we avoid it?

  • @tamillll
    @tamillll Před 4 měsíci +1

    Hi Dan, please add hexagonal architecture video

  • @feloniousmonkey
    @feloniousmonkey Před 3 měsíci

    I agree with most ..a few points of refinement id make though..if you are writing published spring libs that are used elsewhere I would lean in favor of always providing interfaces or coding to a contract.
    I really didn't quite understand the point of arranging code in packages as prescribed although this isn't the first time I've seen this idea... I've never really seen a realistic advantage and if you are doing microservices and have so many different domains that your crossing wires and it's confusing perhaps you've misdrawn your context boundaries ?
    I like this series though and to add to common errors ...I have often come into projects that don't properly use http status codes , a good.example is rest calls that return 200 with an error payload you need to check for..yuck but I see it consistently.
    Exposing dB entities directly and not using dtos is another..and on that note manual mapping between the entity/dto layers when great tools exist for this.
    Another common mistake I see frequently is manual validation and not fully understanding the power of spring validation...
    Prob a dozen others but ...cheers I look forward to your next installment!

  • @Joseph-oz7tx
    @Joseph-oz7tx Před 4 měsíci

    great

  • @zaymaungmaungmyint8142
    @zaymaungmaungmyint8142 Před 2 měsíci

    Dan, Thank for sharning!
    In exception handling, what if we have the controller, service, and repository. Where would be the best place to handle the exception? What would you recommend?
    Controller or service? My throught is controller though.

  • @emmanuelU17
    @emmanuelU17 Před 4 měsíci +1

    Have mercy on folks that watch this at night time. Light mode is a no no 😭

  • @tomislavkovacevic7085
    @tomislavkovacevic7085 Před 14 dny

    So in a package by feature approach, where do you put, for example, your Utility classes? Example DateTimeUtil. Since its not a part of any feature

  • @davidleonardobernal61
    @davidleonardobernal61 Před 4 měsíci

    Great video that tells me that I'm on the right track, but I have a doubt about point 1. By using private classes and having everything in the same package (something that is done a lot in spring projects) if we talk about feature architecture. Wouldn't it be a disadvantage in this case? Since we would surely have a shared domain between all the features and would we break with this encapsulation? What do you think or what alternative do you use for these cases?

  • @pedrolobo9835
    @pedrolobo9835 Před 4 měsíci +1

    Great video.
    There is something I changed recently, because I believe it is a better approach, according to Clean Architecture. Instead of making conversions between DTOs and Entities classes in the controller, I started creating a mapper in an isolated package and letting the services layer request these conversions. What do you think of the idea?

    • @JitterTed
      @JitterTed Před 4 měsíci

      I put the conversions in the DTOs themselves, as they've got the data and it makes testing easy. According to Clean or Hexagonal architecture, the service layer should not be aware of those DTOs.

    • @pedrolobo9835
      @pedrolobo9835 Před 4 měsíci

      @@JitterTed Thanks for commenting. I'm not sure if I understood your suggestion correctly, but who asks to convert the DTOs? Is it the controllers or services layer?

    • @JitterTed
      @JitterTed Před 4 měsíci +1

      @@pedrolobo9835The Controllers obtain (Domain) Objects from the Service layer, and then ask the DTO to convert them to the DTOs. This way the Service layer doesn't have to conform to any particular Controller's needs (it supplies Domain Objects). Typically I have DTOs specific to a Controller (or set of related Controllers).

    • @pedrolobo9835
      @pedrolobo9835 Před 4 měsíci

      @@JitterTed OK. Thanks for that! =)

  • @Phoenix-od2bp
    @Phoenix-od2bp Před 3 měsíci

    Hi Dan, what is your opinion about putting business logic in config files like application yaml to make it extensible. Recently there was a requirement where data had to be filtered based on some fields and these fields could change in future. Someone suggested to put them in configuration files to make it future proof.

  • @TheSlavaG
    @TheSlavaG Před 4 měsíci

    in last example. better to just return optional from repository. And then throw exception from controller.

  • @bitsofdevbrain
    @bitsofdevbrain Před měsícem

    What about the "Resource Oriented design principle" used for designing the REST endpoints? It says that the endpoints should be named after the resources that they are dealing with. But when we are dealing with multiple resources, it says we should use nested endpoints following the resource hierarchy? Is it necessary to follow these?

  • @ax8635
    @ax8635 Před 4 měsíci

    Mistake #6. Do not use streams everywhere and always, they are much slower in most cases.

  • @ravimangalagiri
    @ravimangalagiri Před 4 měsíci

    Dan what theme are you using for the demo. just curious

  • @ratikantapradhan1537
    @ratikantapradhan1537 Před 4 měsíci +1

    In Mistake #1, how to write unit tests if service layer is private ?
    Do we expect to keep Unit test code in same package?

  • @Vityoube
    @Vityoube Před 4 měsíci

    Concerning the mistake 5: is there a way to also set response message (not only response code) for spring to render by some annotation?

  • @jopadjr
    @jopadjr Před 4 měsíci

    245th...Thanks Dan

  • @alibaba40thvs
    @alibaba40thvs Před 4 měsíci

    Hello Dan, do you have any channel through which we can submit our code to you for a code review?

  • @pejko89
    @pejko89 Před 4 měsíci +1

    I'm so proud this video wasn't useful to me. I'm still not a junior, but I've had 2 internships. This is how I do stuff.
    But all of the bad examples show how I did things at some point in the past two years during my learning path

  • @ayushjaiswal4449
    @ayushjaiswal4449 Před 4 měsíci +1

    great tutorial, I think you should make a LinkedIn Course for spring boot where you cover all aspects of spring such as web, security, data etc

  • @eyasuemana6946
    @eyasuemana6946 Před 4 měsíci

    please to on package structuring in spring project. thanks!

  • @DanteMorius1
    @DanteMorius1 Před 4 měsíci +2

    Making everything package private and then putting into Spring context is not a great example of "don't make everything public". If something is in the context then it's available anywhere anyway...

  • @vintage8
    @vintage8 Před 4 měsíci

    I wonder would it be better instead of throwing a TodoNotFoundException create a NotFoundException with a message property and throw it?

  • @vrjb100
    @vrjb100 Před 4 měsíci

    Mistake 6 improper medieatype or missing mediatype. All rest controllers should produce json mediatype and consume it for post/update/patch. There are clever hacks that use improper media type handling.

    • @cosminsel
      @cosminsel Před 4 měsíci

      JSON is not a requirement of REST. You can use other formats.

  • @sirfinsaan
    @sirfinsaan Před 4 měsíci +1

    feature based is good but still require public , moslty need to talk to different package, very rare package is restricted not needed to talk

  • @jackofnotrades15
    @jackofnotrades15 Před 4 měsíci

    Not using constructor injection for @ConfigurationProperties.

  • @kyleryxn
    @kyleryxn Před 4 měsíci

    I'm a little confused about the same mappings, how will the controller know which one to call?

  • @lukwis1000
    @lukwis1000 Před 4 měsíci

    what about summer developers?

  • @sugankpms6169
    @sugankpms6169 Před 4 měsíci

    + light mode.

  • @douglascamiloduartedesousa8349
    @douglascamiloduartedesousa8349 Před 4 měsíci +6

    Hi, Dan! The github repo is private... =/

  • @fakename2415
    @fakename2415 Před 14 dny

    Wait... some people arent using dark mode?

  • @meikuv
    @meikuv Před 4 měsíci

    Color theme name please

  • @Hnzk10
    @Hnzk10 Před 4 měsíci

    Hide the pain Dan

  • @666bananajoe
    @666bananajoe Před 4 měsíci

    I'd say "5 Common Mistakes Spring WEB Developers Make"

  • @pawelmarkisz8783
    @pawelmarkisz8783 Před 3 měsíci

    💖 Promo>SM

  • @joachimdietl6737
    @joachimdietl6737 Před 4 měsíci

    this interface mistake is not really a mistake. I do it all the time

  • @techspinster
    @techspinster Před 4 měsíci +1

    Num 2 is why I like lombok's @RequiredArgsConstructor

  • @143aravinth
    @143aravinth Před 4 měsíci +1

    The git repo is not available @DanVega