Udemy Course Spring Framework 48-Spring Data with another DB

ZONGRU Li
1 min readMar 25, 2019

--

Connect to another database

假定要連的是已建置好的MySQL DB

首先要透過Maven把相關的MySQL Driver抓進來

於pom內將相關的Dependency加入:

並在application.properties加入連線資訊:

spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:mysql://localhost:3306/person_example
spring.datasource.username=personuser
spring.datasource.password=YOUR_PASSWORD

其中 spring.jpa.hibernate.ddl-auto指的是 SchemaManagementTool自動執行

  • none : No action will be performed.
  • create-only : Database creation will be generated.
  • drop : Database dropping will be generated.
  • create : Database dropping will be generated followed by database creation.
  • validate : Validate the database schema
  • update : Update the database schema

(若只想建Table就用create就好)

相關參考:

待研究問題:

連兩個DB?

參考:

https://medium.com/@joeclever/using-multiple-datasources-with-spring-boot-and-spring-data-6430b00c02e7

--

--

ZONGRU Li
ZONGRU Li

Written by ZONGRU Li

2022/11/17 開源部分個人筆記給LINE "Java程式語言討論區"社群,希望能對社群的技術學習做一點點貢獻.(掩面....記得退訂閱!

No responses yet