5 Common Mistakes Spring Developers Make

2024 ж. 22 Мам.
14 178 Рет қаралды

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 ❤️

Пікірлер
  • thanks! writing interfaces, which are never used are waste of time. good to hear this from an experienced spring developer.

    @d2k2@d2k22 ай бұрын
  • 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

    @hirokiminami4194@hirokiminami41942 ай бұрын
  • 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.

    @petritoivari@petritoivari2 ай бұрын
  • Please continue along these line of topics!

    @kassemjenkins@kassemjenkins2 ай бұрын
  • 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)

    @pacifiquemunzihirwa7054@pacifiquemunzihirwa70542 ай бұрын
    • 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?

      @jmrah@jmrah2 ай бұрын
  • It would be amazing to see something similar for spring data jpa

    @darkogrozdanovski@darkogrozdanovski2 ай бұрын
    • I think using JPA when you don't need the complexity is a mistake. 😄

      @JitterTed@JitterTed2 ай бұрын
  • Thank you for the interesting video, and number 6: not dropping by the Spring office hours.

    @VerhoevenSimon@VerhoevenSimon2 ай бұрын
    • Ohh that’s a good one haha 😂

      @DanVega@DanVega2 ай бұрын
  • Thank you Dan. Very insightful.

    @simulbista8846@simulbista88462 ай бұрын
  • as always, thanks for this Dan! You're helping beginners like me in a massive way.

    @koladeam@koladeam2 ай бұрын
  • Very good basic points made here. Clear and concise. Dan delivers 😊

    @tobyzieglerrr@tobyzieglerrr2 ай бұрын
  • Amazing Tutorial Dan! As someone who is exploring Spring, this was a great learning

    @chaitanyashetty6745@chaitanyashetty67452 ай бұрын
  • Dan, thanks for sharing. I hope you will make this a series and add more "mistakes" to the repository and KZhead

    @donaldf.coffin8130@donaldf.coffin81302 ай бұрын
  • Very good advice for a novice like me. Thanks a lot!

    @jacks808@jacks8082 ай бұрын
  • 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.

    @fene2899@fene28992 ай бұрын
  • Thanks for good examples

    @user-ix8tr4ug6q@user-ix8tr4ug6q2 ай бұрын
  • Great video, thanks Dan! Looking forward to the exception video!

    @TonInter@TonInter2 ай бұрын
  • #1 is going to be problematic in the long run IMO. Agree with you about all others!

    @anoopktla@anoopktla2 ай бұрын
  • Very useful content! Thanks!!

    @ficamu2@ficamu22 ай бұрын
  • good topic and easy explanation

    @user-ql1rg9mj9d@user-ql1rg9mj9d2 ай бұрын
  • Keep sharing good practices about coding with Spring.

    @omaradrian80@omaradrian802 ай бұрын
  • learned a lot, thanks Dan

    @isurucumaranathunga@isurucumaranathunga2 ай бұрын
  • 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

    @haroldpepete@haroldpepete2 ай бұрын
  • Kindly continue this series.

    @ikennashonowo9250@ikennashonowo92502 ай бұрын
  • thanks!!! please continue!!!

    @antonslonkin@antonslonkin2 ай бұрын
  • 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.

    @jopadjr@jopadjr2 ай бұрын
  • of course, it is sounds like very good series

    @marcincylkowski3004@marcincylkowski30042 ай бұрын
  • Great content!!

    @Uttkarsh_8@Uttkarsh_82 ай бұрын
  • 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

    @alandosman5002@alandosman50022 ай бұрын
  • i love the feature package organization idea, can you make a video on it?

    @kyleryxn@kyleryxn2 ай бұрын
  • 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.

    @Jedimaster36091@Jedimaster36091Ай бұрын
  • Looking forward to a video about @Transactional annotation and common mistakes while using it.

    @finncrisp9900@finncrisp99002 ай бұрын
  • 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!

    @Skiamakhos@Skiamakhos2 ай бұрын
    • I have done the same by just copying what others do without asking why they did it.

      @DanVega@DanVega2 ай бұрын
  • Thanks!

    @ravimangalagiri@ravimangalagiri2 ай бұрын
    • Wow thank you so much for your generosity. I appreciate you 🤩

      @DanVega@DanVega2 ай бұрын
    • @@DanVega np. what intellij theme did you use for the demo?

      @ravimangalagiri@ravimangalagiri2 ай бұрын
  • Hi Dan, please add hexagonal architecture video

    @tamillll@tamillll2 ай бұрын
  • 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.

    @HandledToaster2@HandledToaster22 ай бұрын
  • please we need more

    @ismailforeveryone6889@ismailforeveryone68892 ай бұрын
  • 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!

    @feloniousmonkey@feloniousmonkeyАй бұрын
  • 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?

    @manjosh1990@manjosh19902 ай бұрын
  • 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 :)

    @Vityoube@Vityoube2 ай бұрын
  • Actually none of them are mistakes. I would call them tips and they are great. Thanks!

    @adamm4739@adamm47392 ай бұрын
  • love it

    @eyasuemana6946@eyasuemana69462 ай бұрын
  • 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?

    @davidleonardobernal61@davidleonardobernal612 ай бұрын
  • Dan what theme are you using for the demo. just curious

    @ravimangalagiri@ravimangalagiri2 ай бұрын
  • in last example. better to just return optional from repository. And then throw exception from controller.

    @TheSlavaG@TheSlavaG2 ай бұрын
  • 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.

    @zaymaungmaungmyint8142@zaymaungmaungmyint814211 күн бұрын
  • 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.

    @Phoenix-od2bp@Phoenix-od2bpАй бұрын
  • Hello Dan, do you have any channel through which we can submit our code to you for a code review?

    @alitariq143@alitariq1432 ай бұрын
  • Concerning the mistake 5: is there a way to also set response message (not only response code) for spring to render by some annotation?

    @Vityoube@Vityoube2 ай бұрын
  • great

    @Joseph-oz7tx@Joseph-oz7tx2 ай бұрын
  • Have mercy on folks that watch this at night time. Light mode is a no no 😭

    @emmanuelU17@emmanuelU172 ай бұрын
  • please to on package structuring in spring project. thanks!

    @eyasuemana6946@eyasuemana69462 ай бұрын
  • 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?

    @pedrolobo9835@pedrolobo98352 ай бұрын
    • 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.

      @JitterTed@JitterTed2 ай бұрын
    • @@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?

      @pedrolobo9835@pedrolobo98352 ай бұрын
    • @@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).

      @JitterTed@JitterTed2 ай бұрын
    • @@JitterTed OK. Thanks for that! =)

      @pedrolobo9835@pedrolobo98352 ай бұрын
  • Mistake #6. Do not use streams everywhere and always, they are much slower in most cases.

    @ax8635@ax86352 ай бұрын
  • I wonder would it be better instead of throwing a TodoNotFoundException create a NotFoundException with a message property and throw it?

    @vintage8@vintage82 ай бұрын
  • I'm a little confused about the same mappings, how will the controller know which one to call?

    @kyleryxn@kyleryxn2 ай бұрын
  • In Mistake #1, how to write unit tests if service layer is private ? Do we expect to keep Unit test code in same package?

    @ratikantapradhan1537@ratikantapradhan15372 ай бұрын
  • Not using constructor injection for @ConfigurationProperties.

    @jackofnotrades15@jackofnotrades152 ай бұрын
  • 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...

    @DanteMorius1@DanteMorius12 ай бұрын
  • 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

    @ayushjaiswal4449@ayushjaiswal44492 ай бұрын
  • feature based is good but still require public , moslty need to talk to different package, very rare package is restricted not needed to talk

    @sirfinsaan@sirfinsaan2 ай бұрын
  • 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

    @pejko89@pejko892 ай бұрын
  • 245th...Thanks Dan

    @jopadjr@jopadjr2 ай бұрын
  • 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.

    @vrjb100@vrjb1002 ай бұрын
    • JSON is not a requirement of REST. You can use other formats.

      @cosminsel@cosminsel2 ай бұрын
  • what about summer developers?

    @lukwis1000@lukwis10002 ай бұрын
  • Color theme name please

    @meikuv@meikuv2 ай бұрын
  • + light mode.

    @sugankpms6169@sugankpms61692 ай бұрын
  • Hi, Dan! The github repo is private... =/

    @douglascamiloduartedesousa8349@douglascamiloduartedesousa83492 ай бұрын
    • Fixed. Thank you for letting me know.

      @DanVega@DanVega2 ай бұрын
    • @@DanVega Thank you, Dan!

      @douglascamiloduartedesousa8349@douglascamiloduartedesousa83492 ай бұрын
    • Mistake #1 making everything public… makes the repo private😂 I lol‘d

      @zombi1034@zombi10342 ай бұрын
    • @@zombi1034 hahaha!

      @douglascamiloduartedesousa8349@douglascamiloduartedesousa83492 ай бұрын
    • @@zombi1034😂😂😂

      @VebitoTetseo_gPlus@VebitoTetseo_gPlus2 ай бұрын
  • Hide the pain Dan

    @Hnzk10@Hnzk102 ай бұрын
  • first viewer..''🎉🎉

    @Bas_Code@Bas_Code2 ай бұрын
    • 🎉

      @DanVega@DanVega2 ай бұрын
  • I'd say "5 Common Mistakes Spring WEB Developers Make"

    @666bananajoe@666bananajoe2 ай бұрын
  • 💖 Promo>SM

    @pawelmarkisz8783@pawelmarkisz8783Ай бұрын
  • this interface mistake is not really a mistake. I do it all the time

    @joachimdietl6737@joachimdietl67372 ай бұрын
  • Num 2 is why I like lombok's @RequiredArgsConstructor

    @techspinster@techspinster2 ай бұрын
  • The git repo is not available @DanVega

    @143aravinth@143aravinth2 ай бұрын
    • Should be now.

      @DanVega@DanVega2 ай бұрын
KZhead