Multiple JDBC Clients - How to configure multiple DataSources in Spring

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

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

  • @null8735
    @null8735 11 หลายเดือนก่อน +2

    As a student who is learning spring by myself, your video is really helpful even im not an Eng speaking country

    • @DanVega
      @DanVega  11 หลายเดือนก่อน +3

      Thank you so much. I love hearing from students and if you have anything you're having trouble with please let me know and I would be happy to help.

  • @djamdev
    @djamdev 11 หลายเดือนก่อน +8

    Interesting! Here's another question in the same direction: How can we implement multi-tenancy with Spring Boot, whether with JDBC or JPA DATA?

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

      May be this might help you get insight. th-cam.com/video/pG-NinTx4O4/w-d-xo.html

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

      Thomas is the best! Thanks for sharing this

    • @peterponzel3422
      @peterponzel3422 8 หลายเดือนก่อน +1

      ✋same here - would be very interesting to see this for a multi-tenancy setup where a DataSource → JdbcClient is picked up during runtime based on some value(s) ... plus have this working with @org.springframework.transaction.annotation.Transactional annotations

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

      +1

  • @Anbu_Sampath
    @Anbu_Sampath 11 หลายเดือนก่อน +1

    Surprised to see co-pilot is spot-on with all the suggestion with Spring convention.
    Also Broadcom part at the start :)

    • @DanVega
      @DanVega  11 หลายเดือนก่อน +2

      I'm still unclear what sources CoPilot is using but it's obvious it's using either my history or local projects because I have an example that I worked up before I recorded this tutorial.

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

      In November my team was told that copilot only used public sources from GitHub along with a subset of the files open in your IDE.

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

    Thank you
    @Dan Vega, You are just a blessing to us the Spring developer

  • @AleksandarT10
    @AleksandarT10 11 หลายเดือนก่อน +3

    Great video Dan! Long overdue! Whats the preffered way to build a datasource from the 2 mentioned? Doesnt the second one create a HikariDataSource anyway?

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

      If you look at the DataSourceBuilder it actually returns a HikariDataSource. I'm not sure there is a "correct" way to do things here, depends on your needs. If you just want a HikariDataSource though either of these will work.

  • @praneethjayawardena7883
    @praneethjayawardena7883 11 หลายเดือนก่อน +4

    Thank you Dan this is really helpful ❤ if you can make a video about restclient with OAuth2 integration calling apis with basic tokens much appreciated 😊 Thanks again 🙂

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

      Thank you for the kind words and the suggestion.

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

    Thank you for the video! Do you plan to create videos about creating and connecting libraries and starters in Spring Boot?

  • @sachinmisal4829
    @sachinmisal4829 11 หลายเดือนก่อน +1

    Could you please make an same example using spring data jpa for multiple datasource instead multiple jdbcclient?
    I would be looking forward to see the video on multiple datasource using spring data jpa.
    Thank you so much for this awesome content.

  • @rafaelestevez9661
    @rafaelestevez9661 11 หลายเดือนก่อน +1

    Nice video! my questions: does this work only for RDBMS? Is it possible to do this with a NoSQL and a SQL one?

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

    Well done Dan. Thanks for the smooth presentation 🙂

  • @JamesStansell
    @JamesStansell 11 หลายเดือนก่อน +1

    At 23:18 why are your properties marked as unknown? You have configuration beans which specify those prefixes. If I recall correctly, in my apps we successfully used the spring.datasource prefix for our xxx and yyy DB config properties. The way you used your own prefix seemed great to me, only i don't understand why the IDE failed to recognize it.

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

      I'm not sure why the IDE is yelling at me, maybe a rebuild would fix it 🤷‍♂️

  • @JaimeReyCasadoMonokepos
    @JaimeReyCasadoMonokepos 11 หลายเดือนก่อน +1

    great one!!!
    it's an elegant solution, but it looks like it won't scalate too well, i am not an expert, but replicating this with a dozen of schemas seems a bit madness.
    Is there another solution, maybe usin JPA or another valid approach?
    Thanks a lot for this and all your videos

    • @DanVega
      @DanVega  11 หลายเดือนก่อน +2

      I'm not sure I can think of a scenario where you have a dozen schemas. In that scenario it might make sense to break your monolith into microservices.

  • @jopadjr
    @jopadjr 11 หลายเดือนก่อน +2

    85th...Thanks Dan. Great video. I learned a lot here mate !!! Maybe if I can suggest a topic on creating an API for a product or employee, etc deployed in the cloud (AWS, Azure, or GCP). Then someone then can use it like anyone writing an Android application.

    • @DanVega
      @DanVega  11 หลายเดือนก่อน +1

      Great suggestion. If you check my channel I have created a few videos on AWS Lambdas

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

    what font did you use? I think I love it

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

    You're doing a great job Dan!

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

      I appreciate that! Thank you

  • @IbrahimOzis
    @IbrahimOzis 11 หลายเดือนก่อน +2

    Thank you 💐

    • @DanVega
      @DanVega  11 หลายเดือนก่อน +1

      Thank you for the question.

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

    How to specify the data source when using JDBC Data Repository interface annotation?

  • @DaviMello
    @DaviMello 11 หลายเดือนก่อน +2

    Sorry, I might be oversimplifying things but couldn’t you have just passed in JDBC values to each bean and then created the DataSources?

    • @DanVega
      @DanVega  11 หลายเดือนก่อน +2

      I'm not sure I understand but If you want to throw together a quick example based on mine that might help.

  • @Talaria.School
    @Talaria.School 14 วันที่ผ่านมา

    thanks, nice topic

  • @ken_burns
    @ken_burns 11 หลายเดือนก่อน +2

    How can this be extended to provide multiple datasources to be used by spring data JPA repositories rather than JDBC clients ?

    • @zoladkow
      @zoladkow 11 หลายเดือนก่อน +2

      Sure - for each datasource you'd create an entity manager factory and a transaction manager (and you need to select which set of those is @Primary). Then for each datasource again you'd use @EnableJpaRepositories to link basePackages with specific entityManagerFactory and transactionManager - and since you'd need as many of those annotation as you'll need datasources, it's simpler to have a separate configuration class for each datasource and associated beans.
      Disclaimer: That's from the top of my head for an older version of Spring Boot. But i think if you search for specs of @EnableJpaRepositories you'll find good examples of multi-datasource JPA configs :)

    • @DanVega
      @DanVega  11 หลายเดือนก่อน +6

      Here is an example of that github.com/spring-projects/spring-data-examples/tree/main/jpa/multiple-datasources

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

      Thanks Dan@@DanVega

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

    Thank you Dan. This helps but does not solve my problem. I am looking for a way to create DataSources and their associated JdbcTemplates dynamically. I do not want to create them at start up. I do not know what my data sources are at startup. And my data sources can change while the SpringBoot app is running. Essentially, I am looking for basics. I looking for the code to create DataSources on the fly, without @Bean, without @Configuration. I am looking to connect to 1 database "writer", and 1 to N database read replicates. I intend to code a "DataSourceManager". Can you point me to a simple example of how to create a DataSource, an associated JdbcTemplate, without beans?

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

    JDBC or JDBC template ? which better ?

  • @saikiranj807
    @saikiranj807 10 หลายเดือนก่อน +1

    Hi Dan! I tried something similar spring data JPA in the past, everything works fine if I use @Primary on one of the beans but spring doesn't autowire some other required dependency beans that are needed if I remove that annotation and everything falls apart, can you explain why that happens?

    • @utkarshsharma7931
      @utkarshsharma7931 8 หลายเดือนก่อน +1

      Can you once try with replacing @Primary wiith @Qualifier on both datasources.

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

    Thank you, Really Awesome

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

    hi Dan is it possible to make two entities with oneTomany relationship and store each one in sperate db ( mysql and postgresql)

  • @vladprudius7622
    @vladprudius7622 11 หลายเดือนก่อน +1

    Still the question is who will use jdbc client (or what are the benefits of using jdbc client) when we have a hibernate ?

    • @DanVega
      @DanVega  11 หลายเดือนก่อน +1

      What if you have a small project and don't need Hibernate? What if you or your team doesn't have experience with JPA? I understand the benefits of JPA but not every project calls for it.

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

      @@DanVega you describe PET project =(

    • @aleksandarvanced5434
      @aleksandarvanced5434 11 หลายเดือนก่อน +2

      Plain Jdbc is king and u have full control. I have seen many people use Hibernate and they struggle with some more complex things

    • @DanVega
      @DanVega  11 หลายเดือนก่อน +1

      @@vladprudius7622 What do you mean by PET project? Like a personal one? if that's the case it's simply not true. I know many large organizations who aren't using JPA

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

    transaction handling is missing. Also the usage of Entitymanager is missing

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

    Sub + Like. Great content!
    Here's another question.
    How would you connect to a DB (let's say Oracle) with mTLS?

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

    Cool color scheme, can you tell me the name? Thank you!

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

    How about video on store the external api response into database and only required feilds from json response will be stored not all the things we get back, i think we will use jackson for that ig

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

      So you call an API and get back an employee object back but you only want to store 5 of the 10 fields in the database. Are you storing the employee object JSON with those 5 fields or more data? Can you email me an example repo of this, would be happy to take a look.

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

      @@DanVega I get an json response of let say 10 properties, and some of the properties are again json block inside it.
      I will store some of the fields of the response and others are ignored. And only the properties we want will be stored into DB,and also one required I'd for table nothing else.
      Also I came across an issue that I am getting a new response from same api every 20 sec and I want to store it using scheduler, but I came across many issues with it.
      I don't have repo for reference sorry

  • @hkkabir2024
    @hkkabir2024 11 หลายเดือนก่อน +1

    i don't really unserstand why JDBC while we are using JPA ? one more thing. i know how to configure multiple datasource in spring with configuration file but the qustion is why? i have used application.properties / yaml gave multiple data source properties there and used both daasource at a time haivng no conflict and no issue. so if we can give all the data soruce config into application.properties and working fine then what is the necessity to use config file for multi datasoruce ???? would you like to explain it plz.

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

      There are pros/cons to JDBC and JPA and I will try to get into that in an upcoming video.
      Do you have a sample where you configure multiple datasources using just properties that I can look at?

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

      @@DanVega youtube is not giving me permission to give link here . i gave u on facbook commnets. would you like to check that

  • @joachimdietl6737
    @joachimdietl6737 11 หลายเดือนก่อน +1

    nice video!

    • @DanVega
      @DanVega  11 หลายเดือนก่อน +1

      Thank you! Cheers!

  • @pablocaiza.
    @pablocaiza. 11 หลายเดือนก่อน +1

    good videos

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

      Thank you!

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

    I think the full screen with code would be better! It does not help to see your face. or may be keep it smaller

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

    sir you are making it too hard

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

    I requested this piece of shit from you a few months ago. But I didn't get a response. Anyway, here we are!

    • @DanVega
      @DanVega  11 หลายเดือนก่อน +4

      I get a lot of questions and unfortunately don't have a good way of organizing them and responding. I'm sorry I didn't get to yours but happy we ended up here with a response.

    • @flaviaamaraldiniz7150
      @flaviaamaraldiniz7150 11 หลายเดือนก่อน +2

      @@DanVegayou are such a gentleman 😅

    • @DanVega
      @DanVega  11 หลายเดือนก่อน +2

      @@flaviaamaraldiniz7150 Life is too short to be involved in such things 🤷‍♂️😂

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

      @@DanVega Hey Dan!
      Didn't mean to offend you. Just expressed my excitement seeing this as this was a long-awaited problem for me.
      I'm really grateful to you, as I have learned a lot from your channel. 😍🤩