【发布时间】:2017-10-28 05:47:39
【问题描述】:
在我的 spring Data 项目中,我更喜欢用data.sql 填充一些数据。它们是图像资源、图标和徽标之类的东西。
我的项目有两个application.properties。一个用于本地开发,另一个用于在具有不同server.adress 的主服务器上发布
我的问题是data.sql 无法从属性中导入变量:
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)
我不能从data.sql 的选定属性中考虑server.address。我想要 http://192.168.34.24:8085 用于开发服务器和 http://192.168.24.250:8080 用于发布。
那么我如何考虑 data.sql 中的 application.properties 变量,或者有更好的方法在起点填充服务器数据?
【问题讨论】:
-
如何执行脚本?你不能设置环境变量 DEV/PROD 可以使用 Spring @Value 或其他设置,然后根据变量加载属性文件。使用命名变量在 .sql 文件中,您可以在执行脚本之前替换加载的属性中的值。
-
@NitinPrabhu 我这样执行:java -jar -Dspring.profiles.active=propertyName application.jar 但无法了解如何在 data.sql 中使用属性变量
标签: spring spring-data server-configuration