我想了解如何遍歷一個YAML屬性文件
讀取配置文件(YAML):
<context:property-placeholder properties-ref="myConfig" />
<spring:beans>
<spring:bean id="myConfig" class="org.springframework.beans.factory.config.YamlPropertiesFactoryBean">
<spring:property name="resources" value="classpath:config.yaml"/>
</spring:bean>
</spring:beans>
和這裏是一個Java組件,它遍歷這些條目:
public class ConfigExample implements Initialisable {
private Properties props;
@Override
public void initialise() throws InitialisationException {
props.entrySet().forEach(entry -> {
// do what ever you want with configuration entries.
// for example System.out.println :)
System.out.println(entry.getKey() + ": " + entry.getValue());
});
}
public Properties getProps() {
return props;
}
public void setProps(Properties props) {
this.props = props;
}
}
注入myConfig
在ConfigExample
:
<spring:beans>
<spring:bean class="ConfigExample">
<spring:property name="props" ref="myConfig" />
</spring:bean>
</spring:beans>
另外,我認爲你不能把入站端點foreach循環mulesoft文件中讀取。如果是這種情況,那我們該如何實現呢?
這是正確的,你將無法遍歷入站端點,但您可以根據您的配置創建入站端點流和啓動它們。法拉茲馬蘇德介紹瞭如何做到這一點。