Spring boot reference file location from resources in properties file

后端 未结 1 376
借酒劲吻你
借酒劲吻你 2021-01-13 20:08

I have a Spring Boot application using Google Pub Sub API. I need to inject Google credentials and other properties using file credentials.json. I put the file

相关标签:
1条回答
  • 2021-01-13 20:20

    If you use the classpath prefix then Spring will look for the file on your classapth.

    If you put the file in src/main/resources then Maven will, by default, copy it to the root of your classpath and it will then be addressable as follows:

    spring.cloud.gcp.credentials.location=classpath:credentials.json
    

    This should hold true whether ...

    • You are running in your IDE; your IDE's Maven integration will copy the file from src/main/resources to the root of your classpath - typically target/classes
    • You are running a built JAR; Maven will copy the file from src/main/resources to the root of your JAR
    0 讨论(0)
提交回复
热议问题