Home > database >  In which database JpaRepository uses by default?
In which database JpaRepository uses by default?

Time:06-23

When we using methods that come from JpaRepository like save, in which database spring boot use? and how can we change the default database if necessary?

@Repository
  
// Interface
public interface FooRepository
    extends JpaRepository<Department, Long> {
}

CodePudding user response:

It uses the database which you have configured in your properties file. You can change the database using the following properties(MySQL example):

spring.datasource.url=jdbc:mysql://localhost:3306/todo_example
spring.datasource.username=todouser
spring.datasource.password=YOUR_PASSWORD

CodePudding user response:

The database url & credentials can be defined in your application.properties file like:

spring.datasource.url=jdbc:mysql://localhost:3306/schemaName
spring.datasource.username=yourUsername
spring.datasource.password=yourPassword

In case you are using multiple databases, you can set one of them as default and specify when you want to access the second one. You can check here on how to do it.

  • Related