Spring Boot uses different database configurations when collaborating with different developers?

when multiple people collaborate to develop a spring boot project, different developers may have different local server configurations for testing. For example, developer A"s local database password is 123456 B the developer"s local database password is root,. If they modify the same application.yaml, the code will conflict.

want to know if you can write your own database configuration separately, which is added to .gitignore and will not be uploaded to git, and then spring boot connects to the database to determine whether there is such a configuration, and if so, use this configuration first.

Nov.09,2021

using profiles can only be said to achieve this goal.
actually spring-boot loading the configuration will look for several directories:

Config locations are searched in reverse order. By default, the configured locations are classpath:/ , classpath:/config/ , file:./ , file:./config/ . The resulting search order is the following:

  1. file:./config/
  2. file:./
  3. classpath:/config/
  4. classpath:/

the loading order is reversed, so you just need to create the same configuration file in workDir to overwrite the same configuration in the classpath directory.

config classpath


  1. @wt1187982580 --spring.profiles.activeprofile
  2. application.yml,application-xxx.ymlapplication.yml,--spring.profiles.active=xxx, : java -jar my_api.jar --spring.profiles.active=xxx
  3. :
    clipboard.png
  4. idea():
    clipboard.png

you can use multiple yml files to configure
application-dev.yml
use spring.profiles.active

application.yml

spring:
  profiles:
    active: dev
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/test
    username: root
    password: root

  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b40dcb-2c530.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b40dcb-2c530.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?