Search code examples
springspring-dataserver-configuration

Spring data best practice for preload data that considers application.properties


In my spring Data project there are some data that i prefer to fill with data.sql. They are some things like Image resources and Icons and logos.

My project have two application.properties. one for local developing and another for publishing on main server that have different server.adress my problem is in data.sql can not import variable from properties:

INSERT INTO sticker_table( sticker_type, sticker_img_url , free_sticker) values (1,'http://192.168.34.24:8085/public/ic_avator_boy_1.png',true)

I can not consider server.address from selected properties in data.sql. I want http://192.168.34.24:8085 for develop server and http://192.168.24.250:8080 for publishing.

So how i can consider application.properties variable in data.sql or is there better way to fill data of server in start point?


Solution

  • According to the spring-data-jpa documentation, you can add a data-${platform}.sql to your spring boot project. You could use that to separate out the difference between your local and remote server with data-local.sql and data-remote.sql. Once you do that, you can control which file to load as follows...

    java -jar -Dspring.datasource.platform=local application.jar
    

    or

    java -jar application.jar --spring.datasource.platform=remote