10 Spring and Spring Boot Common Mistakes You Need To STOP

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 พ.ย. 2024

ความคิดเห็น • 218

  • @codingsavid6509
    @codingsavid6509 ปีที่แล้ว +55

    Can you make a video on propertly error handling?

    • @V4dk4n
      @V4dk4n ปีที่แล้ว

      Read about @ControllerAdvice annotation.

    • @olukayodepaul7070
      @olukayodepaul7070 12 วันที่ผ่านมา

      yes you can check how error is manage with the code base i shared. u can have a custom error manager.

  • @zsombortoreky7678
    @zsombortoreky7678 ปีที่แล้ว +42

    You've mentioned at the testing part, that we should not use a different database from the production one (eg.: postgres / h2), I would really be interested in seeing a video about these types of best practices, thanks😁

    • @mikeoxlongdnb
      @mikeoxlongdnb ปีที่แล้ว

      th-cam.com/users/livev3eQCIWLYOw

    • @nicholasferrara8028
      @nicholasferrara8028 5 หลายเดือนก่อน +2

      You want to look in to using Test Containers to achieve this

  • @rhumedisi2783
    @rhumedisi2783 ปีที่แล้ว +16

    Thank you very much for this detailed Spring/Spring Boot, "How Not Tos". It's great to see a teacher who consistently and effectively communicate best practices.

    • @marcoreinaldi4193
      @marcoreinaldi4193 ปีที่แล้ว

      I agree. I think this video is great and give me insight how to avoid mistake on Springboot. But I hope, he will publish another video with the solution on how to do it right. Not the whole thing, but maybe just an Idea how to do it right.

  • @andreinovosiolov
    @andreinovosiolov ปีที่แล้ว +4

    Thank you for this video. I'm a trainee and you videos are very helpful. Waiting for lesson about proper testing of a Spring Boot application.

  • @aminesafi7261
    @aminesafi7261 ปีที่แล้ว +61

    For the @Autowired annotation, you should use it if you have more than one constructor otherwise Spring will fail to inject the dependencies, it is a kind of a hint to tell spring which constructor to use.
    Nice video and very good explanation, keep going 💪🏻

    • @igle85
      @igle85 ปีที่แล้ว +11

      You shouldn't have 2 constructor for services, it's not a good practice.

    • @aminesafi7261
      @aminesafi7261 ปีที่แล้ว +13

      @@igle85 I agree, I’m just explaining that we can find ourselves in this situation.

    • @Denys.Stoianov
      @Denys.Stoianov ปีที่แล้ว

      @@aminesafi7261 it is possible to pass multiple services to the constructor and it will works even without @Autowired annotation,

    • @aminesafi7261
      @aminesafi7261 ปีที่แล้ว

      @@Denys.Stoianov You didn't get it, read my comment again :)

    • @aminesafi7261
      @aminesafi7261 ปีที่แล้ว

      @@sweets7092 Your comment is off topic, thanks anyway 🙂

  • @marcelohmg
    @marcelohmg ปีที่แล้ว +7

    I would really like a video about testing the databese and querys!

  • @ПавелСмирнов-й7х
    @ПавелСмирнов-й7х 8 หลายเดือนก่อน

    wow it's 2024 and you're still the best spring youtuber in the whole world

    • @andiuptown1711
      @andiuptown1711 4 หลายเดือนก่อน

      *Nah Bouali Ali/Dan Vega/Java Guides/DevTiro are better*

  • @Maicrash104
    @Maicrash104 ปีที่แล้ว +5

    To Error handling, since Spring 6 you can use "Problem Details" like standard and not have your own ErrorDto

  • @rockdarko440
    @rockdarko440 ปีที่แล้ว +17

    Thanks for this! I would really indeed like a video for the case against using H2 for testing. We use Oracle in production (migrating to postgres enterprise in a year or so) and would like to hear what you would suggest here. Thanks again!! :)

    • @MarcoS-mx1vj
      @MarcoS-mx1vj ปีที่แล้ว +3

      The problem with using In-Memory databases for testing is, that it doesn't make your tests reliable. Its a completeley different database with a different feature set. A green h2-based test doesn't mean that your code will work in production as well. One solution for this would be using a dockerized version of your production database (e.g. by using TestContainers).

    • @rockdarko440
      @rockdarko440 ปีที่แล้ว +2

      @@MarcoS-mx1vj Yes, you are ultimately right and Oracle supplies such containers. But the reality often is that developers don't always have the resources on their laptops to run something as hungry as oracle (even containerized that is a beast) and most of all often lack the knowledge/will to set it up. As an ops I would need to create a deployment for them I guess. It's a real shame to be honest, but that is the reality I deal with personally. The model we use for the time being is devs use H2 locally on their laptop, then deploy in a DEV environment where a full blown Oracle server is and although I wish it weren't that way, it does the job. Thanks for replying!

  • @narek-tm
    @narek-tm ปีที่แล้ว +3

    Thanks for your content. Please, make video tutorials on testing in Spring Boot, especially integration testing, test containers.

  • @dshakya29
    @dshakya29 ปีที่แล้ว +2

    Hi Nelson, please make a series on testing Spring Boot applications.

  • @nospamallowed4890
    @nospamallowed4890 ปีที่แล้ว

    Thank you, I did not know about records. Seems like a pretty essential, powerful, and very simple to use feature.
    If I might suggest a topic for a future tutorial that has NOT been covered properly by anybody: Spring Boot 3 + Spring Security 6 + Tomcat 10 (deploy webapp as WAR) + Azure AD authentication & authorization using Microsoft's spring-cloud-azure-starter-active-directory Maven dependency.
    For extra points or as part of another tutorial... how to handle libraries (like the microsoft dependency above) that use logback when you are deploying to a Tomcat 10 that is configured for log4j2 logging (throws a logback exception when it tries to cast LogbackServletContainerInitializer to jakarta ServletContainerInitializer).
    Both of the tutorial topics I mention are fairly common configurations that nobody seems to be covering.

    • @robertwhite3503
      @robertwhite3503 ปีที่แล้ว

      I often use the actual entities rather than DTO's. These may work with persistence, but I cannot see a sensible way to use records with annotation-based data validation.

  • @TheSpiderWalk
    @TheSpiderWalk ปีที่แล้ว +5

    It would be nice to record one video only about testing in spring-boot, I am currently struggling with testing in spring-boot.

  • @tedac091
    @tedac091 ปีที่แล้ว +1

    I've been looking up on how to make the switch from H2 database to tests containers. I would really appreciated a video on it, thank you!

  • @geni4551
    @geni4551 ปีที่แล้ว +2

    Thank you very much for the explanation. Would love to see why we should not use H2 for testing video! :)

  • @glitchinLife
    @glitchinLife ปีที่แล้ว

    A small glance of how beautiful code can be, thanks for sharing

  • @feloniousmonkey
    @feloniousmonkey ปีที่แล้ว +1

    @Valid was correct...@Validated is for partial or group based validation...

  • @heduardos26
    @heduardos26 ปีที่แล้ว +2

    Great video, thanks a lot! We'll love to see a video where you explain how to test with the same DB and not use H2.

  • @sz_peter
    @sz_peter ปีที่แล้ว +4

    Setter injection is allowed when more then 7 dependencies required in the given class to avoid the "Method should not have more then X parameters" Sonar issue (if you use any static code analysis tools).

    • @hamsandwich123
      @hamsandwich123 ปีที่แล้ว +2

      tbf if you have 7 dependencies for a class you may want to rethink your design. good chance the class is doing too much and can be broken up into smaller classes.

  • @Jebusankel
    @Jebusankel หลายเดือนก่อน

    Instead of defining your own ApiError, I think you should strongly consider using the standard and built in ProblemDetail class. It has an RFC.

  • @richaveli
    @richaveli ปีที่แล้ว +3

    Can't wait to see what mistakes I'm already making! 😊

  • @MrTutiplengo
    @MrTutiplengo ปีที่แล้ว +1

    Awesome content. I'm new to Spring Boot and this was very informative. I didn't know about Java records at all.

  • @rostomnouisser4023
    @rostomnouisser4023 ปีที่แล้ว +1

    please make tutorials about XLD , Jenkins and déploiement of an application , it's important and you can make it simple

  • @majesty8309
    @majesty8309 8 หลายเดือนก่อน

    I have learnt something new. Thank you very much Nelson

  • @kirasign4605
    @kirasign4605 ปีที่แล้ว

    Please make other testing video like what you said in this video. Very grateful for this
    Thanks in advance! Lovely videos like always

  • @shortcutcoder6228
    @shortcutcoder6228 13 วันที่ผ่านมา

    At 5:19 you mentioned that there is no need to use @Autowired when doing dependency injection. It actually works when there is only a single constructor. When there are multiple constructor, then you need to explicitly show dependency injection by using @Autowired annotation

  • @bashirzamani5144
    @bashirzamani5144 ปีที่แล้ว

    Thank you nelson, please continue this form of videos

  • @niaboktruk
    @niaboktruk 8 หลายเดือนก่อน

    Amazing content man, I'll watch every video you have. Amazing, simply amazing!!! 🤩

  • @danielbaptista4925
    @danielbaptista4925 ปีที่แล้ว +8

    Hi Nelson! :) Great video, I would love to see a video about database testing with an practical example

    • @482ksd
      @482ksd ปีที่แล้ว

      Second this. Would love to see how you spin up a container with a real DB in it for testing.

    • @Jumataev
      @Jumataev ปีที่แล้ว

      Me also

  • @carlosrenesoto9650
    @carlosrenesoto9650 ปีที่แล้ว

    Great video @amigoscode Thanks a lot for sharing your knowledge!

  • @Denys.Stoianov
    @Denys.Stoianov ปีที่แล้ว +2

    I see that you have here at 12:00 FakeS3 class, so it means you modify your production code to be able to test it. Why you do not use in this case localstack, it is also a standard defacto like testcontainers for testing. Correct me if I am wrong and this is just for Demo purpose

  • @egamberdijabborov6586
    @egamberdijabborov6586 ปีที่แล้ว +1

    👍👍👍👍Thanks for the video tutorial

  • @sphesihlemanuel2933
    @sphesihlemanuel2933 ปีที่แล้ว +1

    Happy to learn, I thought Field injection was the that makes it hard to unit test, and Setter and Constructor injection were fine 👏🏾

    • @adambickford8720
      @adambickford8720 ปีที่แล้ว

      Not setter injection. An object should be in a useable state once its created. Beans are shared by default so you don't want other playing games with it.

    • @robertwhite3503
      @robertwhite3503 ปีที่แล้ว

      Constructor injection offers the guarantee that the object has the required dependencies. Setter injection means that anyone using the object has to remember to inject.

  • @abhipatel439
    @abhipatel439 ปีที่แล้ว +1

    Hey, brother! If it's alright with you, could you possibly make a dedicated video that covers the topic of testing in Spring Boot? It has the potential to greatly benefit your audience.

  • @LearncodewithMuneeb
    @LearncodewithMuneeb ปีที่แล้ว

    Thanks sir for making useful videos for us.
    But I request you very respectfully to work in a project in spring boot having at least 6 entities/tables using spring boot in the back end and React/Angular/Next in the front end

  • @pguti778
    @pguti778 ปีที่แล้ว

    Very good video! Yes please go ahead and do a video on testing!! Another mistake: not using lombok!!!

  • @adarshverma3372
    @adarshverma3372 ปีที่แล้ว

    Please make a video on testing Spring Boot Application using Data Sources

  • @mujaddidsislam1897
    @mujaddidsislam1897 ปีที่แล้ว

    this video gives me enlightenment, جَزَاكَ ٱللَّٰهُ

  • @LukmanJaji
    @LukmanJaji ปีที่แล้ว

    Salam alykun Nelson. Please make a video on why we should not use H2 for testing. Thank you.

  • @andrewcbuensalida
    @andrewcbuensalida หลายเดือนก่อน

    Mistake number 3, not silencing your phone while recording a tutorial. just kidding, i love your videos👍

  • @bladerunner20446
    @bladerunner20446 ปีที่แล้ว +2

    Great content as always. Could you please make more in-depth testing videos

  • @rajkhare5949
    @rajkhare5949 ปีที่แล้ว +3

    nice video thanks!!!...why your courses are not available at Udemy??...please start your channel there as well!!

  • @jochanoss
    @jochanoss ปีที่แล้ว

    Essalamu Aleytkum Nelson, I love the way that your IDE looks. Would you make a video of what plugins do you use?

  • @mark6662
    @mark6662 ปีที่แล้ว

    I understand for most instances constructor injection is better than setter injection but what do you mean by you can't mock the dependencies with setter injection. Surely you can just Create the object and then create a mock of the dependency and pass that dependency in through the setter.

  • @usamaabubakar3061
    @usamaabubakar3061 ปีที่แล้ว

    Can you give more insights about that logger part? What to log, what not to log, best way to use log, and when to use info, debug, warn and error

  • @diniomar3965
    @diniomar3965 ปีที่แล้ว

    Your video is very clear. Whats your setup?

  • @aayush481
    @aayush481 ปีที่แล้ว

    Hi @Amigoscode, your'e an amazing teacher and mentor, we want to buy your full stack course and learn from you, however the price is too high for people in India, as we have to pay in USD...

  • @Michaeljamieson10
    @Michaeljamieson10 ปีที่แล้ว

    Highly recommend his full stack course

  • @mdameenhasan6676
    @mdameenhasan6676 ปีที่แล้ว +1

    Assalam mu alaikum brother, Can you please make video on Muslim Software Engineer Routine in Ramadan… eagerly wait for it😊. And yes love from India🫶🏻

  • @eduardo-1822
    @eduardo-1822 ปีที่แล้ว

    So cool, very nice tips, thank you buddy

  • @rezaru2000
    @rezaru2000 5 หลายเดือนก่อน

    Excellent! to the point!

  • @DeGoya
    @DeGoya ปีที่แล้ว +5

    Salamu alaykum brother, could you do a video on @Async and CompletableFuture?

  • @mriduljayan4466
    @mriduljayan4466 ปีที่แล้ว

    Though xml is verbose it does separation of concerns better. The framework is less invasive as all you have is pojos.

  • @larcenmenlahcen5998
    @larcenmenlahcen5998 ปีที่แล้ว

    Salam alikom akhy(Brother) good job, keep do it. Ramadan moubarak👉

  • @sakthisomaskandan6438
    @sakthisomaskandan6438 ปีที่แล้ว

    Great video as always! Can you please make a video on why not to use h2 for testing? Thanks 🙏

  • @feloniousmonkey
    @feloniousmonkey ปีที่แล้ว

    Great content...your points are ones that I do see fairly often. Keep the vids coming 😀

  • @zafarboymurotov764
    @zafarboymurotov764 ปีที่แล้ว

    Thank you very much good luck

  • @lmrl021
    @lmrl021 ปีที่แล้ว

    Great video. Can I request for another video for possible solution in one of those mistakes? Thank you.

  • @Jumataev
    @Jumataev ปีที่แล้ว +2

    Hello Nelson! I really would like to see how you test with real database, because recently I saw your video with a h2 in junit testing.

    • @robertwhite3503
      @robertwhite3503 ปีที่แล้ว

      It is interesting that so may demos use H2 for testing.

  • @riccardoatwork5291
    @riccardoatwork5291 11 หลายเดือนก่อน

    The main reason to use dependency injection is NOT "to have Spring do things for you" or "so that you can use singletons".
    It is used to do dependency INVERSION.
    Also, leaving the @Autowired on constructors is not a mistake, it servers a role as documentation.

  • @darpanshirsat1712
    @darpanshirsat1712 9 หลายเดือนก่อน

    Thanks you Buddy!

  • @ms-pf9ow
    @ms-pf9ow ปีที่แล้ว

    I learned a lot. Thank you

  • @GFunkEra1992
    @GFunkEra1992 ปีที่แล้ว

    Thank you brother, very usefull info

  • @khaganimammadli6846
    @khaganimammadli6846 6 หลายเดือนก่อน

    Hi, you are my fav youtuber, you explain clearly and i understand almost everything. I wait from you the best tutorial about functional programming, lamda, streams and etc from zero to hero with simple explanation

  • @stefanoriffaldi84
    @stefanoriffaldi84 ปีที่แล้ว +1

    if you pls record video how to avoid H2 in testing, should be amazing

  • @talbiabdelali5914
    @talbiabdelali5914 ปีที่แล้ว

    Could you release a full course of Spring boot testing please ?

  • @gabrieldragone
    @gabrieldragone ปีที่แล้ว

    One of the best videos on the channel! Congratulations again, you are an inspiration!

  • @sphesihlemanuel2933
    @sphesihlemanuel2933 ปีที่แล้ว

    Please record a video on testing 👏🏾🙏🏾

  • @monsuruokuniyi1234
    @monsuruokuniyi1234 ปีที่แล้ว +1

    Tests, I'm not doing that enough. We write lots of code at work, and I believe we should also be writing tests along side. But our output rate doesn’t allow it. Can we start writing tests now? It looks like a daunting task

  • @sweetphilly2
    @sweetphilly2 ปีที่แล้ว

    Yeah i gotta take some time to learn more about Records. They seem simple yet powerful. Anyone seeing the benefits of them, and mind further explaining their uses?

  • @limobei5042
    @limobei5042 ปีที่แล้ว

    Thanks a lot. I learned a lot.
    Please let me know, how i can learn better testing within spring boot, e.g. use right and necessary parts of apllication context

  • @MizanurRahman-fi2qu
    @MizanurRahman-fi2qu 3 หลายเดือนก่อน

    Thank you

  • @sacmaliyoruz
    @sacmaliyoruz ปีที่แล้ว

    salam alaikum brother thanks for everything. you are the best. hi from türkiye

  • @shanagondaarun2436
    @shanagondaarun2436 ปีที่แล้ว +1

    What's the theme called. How to apply it. Looks dope

  • @StefanoRiffaldi
    @StefanoRiffaldi ปีที่แล้ว

    video about exception handler and validation RIGHT NOW

  • @jorgetovar621
    @jorgetovar621 ปีที่แล้ว

    Whats the theme that you are using? it looks nice

  • @AdnanAmmanUllah
    @AdnanAmmanUllah ปีที่แล้ว

    could you please create a detailed video on error handling?

  • @nayeemrafsan356
    @nayeemrafsan356 ปีที่แล้ว

    this is goldmine!

  • @TheKanoxa
    @TheKanoxa ปีที่แล้ว

    Please please please do a video on testing database without H2. I'm struggling in my work with this 😢

  • @matthewsuprunov4497
    @matthewsuprunov4497 ปีที่แล้ว

    great video! well explained, thanks
    can you please show how to manage authentication with jwt, redirecting after success login and managing roles?

  • @henrikkrievs4274
    @henrikkrievs4274 ปีที่แล้ว

    Love your vids. Are you familar with a tool, which is capable of listening to several ports on localhost, at the same time? Like a sniffer

  • @ollySun
    @ollySun ปีที่แล้ว

    How is the fasting going? hope its good. Please do a complete tutorial video on testing

  • @marian2221
    @marian2221 หลายเดือนก่อน

    Nice video. I am not sure however what you aimed to do in "Error Handling" example, but in a form you have shown the code I do not see what is the point to add RuntimeException as Exception is superclass and will catch it.

  • @feloniousmonkey
    @feloniousmonkey ปีที่แล้ว +1

    Your points are valid, but I don't think record really matters in terms of exposing internal data..you are on the right path, mapping your entity to dto like that is pretty crude..of course in the real world tools like mapstruct or dozer are used to seamlessly map to DTOs.

  • @lone_warrior3672
    @lone_warrior3672 ปีที่แล้ว

    Can you please make a video series on Java 8 Stream APIs.

  • @skynight5207
    @skynight5207 ปีที่แล้ว

    Could you please make video about domain driven design (ddd) design pattern with spring boot?

  • @nikolayverkhovtsev3886
    @nikolayverkhovtsev3886 ปีที่แล้ว +1

    Is this IDEA or what IDE u use in this video?

  • @zezoms
    @zezoms ปีที่แล้ว

    Great content. Keep going

  • @shefeeqpm5413
    @shefeeqpm5413 ปีที่แล้ว

    404 status code can be security breach sometimes. It leakes information whether some user exist in system or not. In that case its better to return 500. :)

    • @MarcoS-mx1vj
      @MarcoS-mx1vj ปีที่แล้ว +2

      The way i learned it is to return 404 for the three cases 401, 403 and 404. With this you don't leak sensitive information. 500 would work as well of course, but seems to me a bit odd :)

    • @IvanRandomDude
      @IvanRandomDude ปีที่แล้ว +1

      Few tries with random username and any "hacker" with half brain will figure out that your 500 means 404 :)

    • @shefeeqpm5413
      @shefeeqpm5413 ปีที่แล้ว +1

      @ivan The intention is to lower the risk or not to mitigate :)
      If some one want to hack a system no status code can help :)

    • @ghasemsadeghi5175
      @ghasemsadeghi5175 ปีที่แล้ว

      You can use 400 (Bad Request) too if you are serious about 404

  • @khalilbouali3480
    @khalilbouali3480 ปีที่แล้ว

    thanks a lot !

  • @BioDetermination
    @BioDetermination ปีที่แล้ว

    @Amigoscode Another mistake what I have seen is not using springdoc to generate OpenAPI documentation. This is a lifesaver to deliver to QA instead of using Microsoft Word.

    • @amigoscode
      @amigoscode  ปีที่แล้ว +2

      Maybe I’ll do a video on it

  • @abdullaermatov1848
    @abdullaermatov1848 ปีที่แล้ว +1

    Would you suggest to use Lombok annotations for getter and setters? Or it is better to do it without lombok?

  • @sylvereleipertz955
    @sylvereleipertz955 ปีที่แล้ว

    Good advices for beginners but most of them are not spring boot related. Using DTOs/Records to decouple the database schema from the frontend side or not calling directly the repository in the controller are best practice in every languages

    • @andiuptown1711
      @andiuptown1711 4 หลายเดือนก่อน

      I think because ppl don’t know that records can be used in whatever version of Java they’re using

  • @simpaticode
    @simpaticode 5 หลายเดือนก่อน

    It's constructor vs setter injection, btw.

  • @ayed-al-nator
    @ayed-al-nator ปีที่แล้ว

    nice video ❤❤ thanks

  • @AmaanHasanDilawar
    @AmaanHasanDilawar ปีที่แล้ว +1

    Awesome

  • @taners
    @taners ปีที่แล้ว

    hi Nelson, good tricks thank you. which plugins do you use on IntelliJ ?

  • @jasper-3338
    @jasper-3338 ปีที่แล้ว

    2. Using records, could have some extra explanation as what it does underwater, basically I use a record with the same variabele name and it looks up a record with that variable name? and returns me a single entity with that name? or multiple within that record?
    3. Dependancy @Autowired vs constructor injection, the constructor injection is very good for testing the classes as it can be mocked using mockito. @Autowired is deprecated by spring boot.
    Good that you give one line for testing, as for testing the dependent classes can be mocked.
    For the testing is there a sample I can look into ? So I can speed up my own code as well? :)

  • @ClaudesGomes
    @ClaudesGomes ปีที่แล้ว

    what extensions do you use in the intellij?

  • @danielthompson3082
    @danielthompson3082 ปีที่แล้ว

    what's the difference between @SpringBootTest and @DataJPATest and why should I only use the former once?