SAP Commerce配置属性的优先级
https://help.sap.com/viewer/b490bb4e85bc42a7aa09d513d0bcb18e/1905/en-US/8b8e13c9866910149d40b151a9196543.html
優先級從高到低:
這張表一目了然:
不推薦修改platform文件夾下面的project.properties文件,原因如下:
如何在代碼里訪問properties
SAP Commerce properties are provided in the global ApplicationContext. With this, you can inject a specific value by using the usual Spring notation:
<bean class="Foo"><property name="bar" value="${key_of_property}"/> </bean>The properties are provided by PropertyPlaceholderConfigurer with hybrisPropertiesConfigurer id, which gets the hybrisProperties bean injected. This bean fulfills the java.util.Properties class and holds all properties. You can use this bean in other scenarios too, especially if you want to use the SAP Commerce properties in your WebApplicationContext, having the global ApplicationContext as a parent. For this, define:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="properties" ref="hybrisProperties"/> </bean>關于ref的用法,可以參考這個例子:
BankService類:
Account是一個接口,有set和get方法。
bean.xml:
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd"><bean id="accountDetails" class="com.jwt.spring.AccountImpl" /><bean id="bankservice" class="com.jwt.spring.BankService"><property name="accdetails"><ref bean="accountDetails" /></property></bean></beans>Be aware that this mechanism is not tenant aware. You always get the properties of the master tenant and you do not recognize changes to properties done at runtime. As the configurator is a BeanFactoryPostProcessor, it gets applied once at a startup of a context.
測試代碼:
package com.jwt.spring;import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;public class Test {public static void main(String[] args) {ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");BankService bankSer = (BankService) context.getBean("bankservice");bankSer.withdraw(1000000, 2000.00);bankSer.deposit(1000000, 2000.00);} }ServiceLayer的訪問方式:
On the ServiceLayer, SAP Commerce configuration is reachable using the ConfigurationService. Calling the getConfiguration() method returns a Configuration object. By factory default implementation, the returned object is a HybrisConfiguration object, as shown in the UML diagram.
最佳實踐
A common practice to override property values is to copy individual properties from the project.properties and to paste them into the local.properties file with an edited value.
可以利用JVM的啟動參數:
java -Dfoo=“some string” SomeClass
等價于:
This is the equivalent to adding the following lines to the local.properties file, but the VM parameters are runtime only:
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
總結
以上是生活随笔為你收集整理的SAP Commerce配置属性的优先级的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 平安健康战略合作日健中外,打造冠心病患者
- 下一篇: 马斯克社交小号意外曝光 潜水发文:你喜欢