如何从 local.properties 获取配置数据到 impex?
How to get config data from local.properties to impex?
是否可以从 local.properties 配置文件中定义的环境变量中获取值并通过 impex 文件访问它?
例如
$someMacro=<some variable from config>
谢谢!
您可以将此添加到您的 impex 中:
# Import config properties into impex macros
UPDATE GenericItem[processor=de.hybris.platform.commerceservices.impex.impl.ConfigPropertyImportProcessor];pk[unique=true]
您在 local.properties 等中的所有配置现在都已加载,可以通过 $config-
前缀使用,例如:
local.properties
your.config.property=322
所以你的 impex 看起来像:
# Import config properties into impex macros
UPDATE GenericItem[processor=de.hybris.platform.commerceservices.impex.impl.ConfigPropertyImportProcessor];pk[unique=true]
$variable=$config-your.config.property
INSERT_UPDATE SampleItem;code[unique=true];name
;sample1;$variable
# OR you can just directly use the config macro
INSERT_UPDATE SampleItem;code[unique=true];name
;sample1;$config-your.config.property
希望这对你有用。
编辑:另请注意,如果没有找到这样的 属性,则上述示例中存储的值应完全为:$config-your.config.property
.
要完成 @Atsusa Kai answer,可以避免单独使用 header 的行。
让这一行只是为了加载属性是相当丑陋的......但这实际上是 ConfigPropertyImportProcessor
class 评论中提到的内容:
/**
* Impex ImportProcessor that injects all config properties as impex definitions.
* All defined configuration properties are added as impex macro definitions with
* the prefix of "config-". For example the config key <tt>mail.smtp.server</tt>
* can be accessed via the macro <tt>$config-mail.smtp.server</tt>.
* In order to use this import processor and to load the configuration properties
* the following must be added to the top of the impex file:
*
* <tt>UPDATE GenericItem[processor=de.hybris.platform.commerceservices.impex.impl.ConfigPropertyImportProcessor];pk[unique=true]</tt>
*/
替代方法是使用为此类操作量身定制的 beanshell 命令。
您可以将 UPDATE GenericItem 行替换为
#%new de.hybris.platform.commerceservices.impex.impl.ConfigPropertyImportProcessor().init(impex)
但您需要启用代码执行。
是否可以从 local.properties 配置文件中定义的环境变量中获取值并通过 impex 文件访问它?
例如
$someMacro=<some variable from config>
谢谢!
您可以将此添加到您的 impex 中:
# Import config properties into impex macros
UPDATE GenericItem[processor=de.hybris.platform.commerceservices.impex.impl.ConfigPropertyImportProcessor];pk[unique=true]
您在 local.properties 等中的所有配置现在都已加载,可以通过 $config-
前缀使用,例如:
local.properties
your.config.property=322
所以你的 impex 看起来像:
# Import config properties into impex macros
UPDATE GenericItem[processor=de.hybris.platform.commerceservices.impex.impl.ConfigPropertyImportProcessor];pk[unique=true]
$variable=$config-your.config.property
INSERT_UPDATE SampleItem;code[unique=true];name
;sample1;$variable
# OR you can just directly use the config macro
INSERT_UPDATE SampleItem;code[unique=true];name
;sample1;$config-your.config.property
希望这对你有用。
编辑:另请注意,如果没有找到这样的 属性,则上述示例中存储的值应完全为:$config-your.config.property
.
要完成 @Atsusa Kai answer,可以避免单独使用 header 的行。
让这一行只是为了加载属性是相当丑陋的......但这实际上是 ConfigPropertyImportProcessor
class 评论中提到的内容:
/**
* Impex ImportProcessor that injects all config properties as impex definitions.
* All defined configuration properties are added as impex macro definitions with
* the prefix of "config-". For example the config key <tt>mail.smtp.server</tt>
* can be accessed via the macro <tt>$config-mail.smtp.server</tt>.
* In order to use this import processor and to load the configuration properties
* the following must be added to the top of the impex file:
*
* <tt>UPDATE GenericItem[processor=de.hybris.platform.commerceservices.impex.impl.ConfigPropertyImportProcessor];pk[unique=true]</tt>
*/
替代方法是使用为此类操作量身定制的 beanshell 命令。
您可以将 UPDATE GenericItem 行替换为
#%new de.hybris.platform.commerceservices.impex.impl.ConfigPropertyImportProcessor().init(impex)
但您需要启用代码执行。