如何使用Spring应用程序上下文xml中的varargs?
java -jar my.jar --variable=value
应用程序的context.xml
<bean id="fooClassInstance" class="my.package.FooClass">
<property name="myproperty" value="${variable}" />
</bean>
尝试使用系统属性:
java -Dvariable=value -jar my.jar
这可以开箱即用,或者你需要告诉应用程序上下文在扩展变量时查看系统属性。我尝试了一段时间了。
一个很好的起点是PropertySourcesPlaceholderConfigurer
。
当您在Spring XML配置中执行此类操作时
<bean id="fooClassInstance" class="my.package.FooClass">
<property name="myproperty" value="${variable}" />
</bean>
Spring使用qazxsw poi在系统/环境变量和/或预定义属性文件列表中搜索这些变量。
因此,最简单的方法是使用PropertyPlaceholderConfigurer
将该值作为系统或环境变量传递。
如果你想将这些值作为参数传递给-Dvariable=value
,你仍然可以做像黑客一样的黑客攻击
min