Search code examples
springyamldatasourceh2working-directory

Can I set a working directory for a spring.datasource.url using a YAML file?


So I have an application.yaml like this:

server:
  port: 8090
spring:
  output:
    ansi:
      enabled: ALWAYS
datasource:
    url: jdbc:h2:file:~/Documents/database
    username: xxx
    password: xxx

Is it possible to create that database file always in the directory that has the Application.java file? So if I relocate my file to an other folder I don't have to change what's behind the url?


Solution

  • datasource:
        url: jdbc:h2:file:./
        username: xxx
        password: xxx
    

    This will create it in the relative directory where your application is placed. It would be the same directory where the jar is placed.