【发布时间】:2014-02-14 18:24:02
【问题描述】:
我需要在我的applicationContext.xml中设置一个参数值接口IP地址
我从属性文件中读取此设置并以这种方式使用它:
<bean id="hazelcastInterface" class="com.hazelcast.config.InterfacesConfig">
<property name="interfaces">
<list>
<value>${interface.ip_address}</value>
</list>
</property>
<property name="enabled" value="true" />
</bean>
现在我需要从命令行参数中获取这个值。我使用 Apache Commons CLI 解析器,解析参数并从中创建我自己的 bean commandLineConf 并将其设置为 ApplicationContext。
ExternalBeanReferneceFactoryBean.setInstance("commandLineConf", conf);
beanFactory.registerBeanDefinition(
"commandLineConf",
BeanDefinitionBuilder.rootBeanDefinition(
ExternalBeanReferneceFactoryBean.class)
.getBeanDefinition());
GenericApplicationContext rootAppContext = new GenericApplicationContext(
beanFactory);
rootAppContext.refresh();
但我不知道如何从 applicationContext.xml 中的这个 bean 获取值。我尝试了很多方法,例如但这对我不起作用。
<bean id="hazelcastInterface" class="com.hazelcast.config.InterfacesConfig">
<property name="interfaces">
<list>
<value>#{commandLineConf.ipAddress}</value>
</list>
</property>
<property name="enabled" value="true" />
</bean>
我做错了什么?
【问题讨论】:
-
是的,我的部分源代码来自这个问题...