问题描述
在Spring的applicationcontext.xml文件中使用#{systemProperties ['environment']}是否返回与环境相关的值?
Does using #{systemProperties['environment']} in the applicationcontext.xml file of Spring return the value associated with environment?
或者有没有办法ge春天applicationcontext.xml文件中的系统变量值。
Or is there any way to ge the system variable value in the spring applicationcontext.xml file.
推荐答案
您可以通过不同方式访问系统属性:
You can access the system properties in different ways:
-
#{systemProperties ['databaseName']}
-
#{systemProperties.databaseName}
-
$ {databaseName}
// $而不是#!!
#{systemProperties['databaseName']}
#{systemProperties.databaseName}
${databaseName}
//$ instead of # !!
With #{systemProperties.databaseName}
you have access to the system properties readed for example from the command line (-DdatabaseName="testDB"
).
使用 $ {databaseName}
,您可以访问属性中的属性例如,由PropertyPlaceholderConfigurer 加载并提供给系统专业的文件
With ${databaseName}
you have access the the properties from the properties files loaded and provided for example by the PropertyPlaceholderConfigurer and to the system prooperties too
@Value("#{systemProperties['java.version']}")
private String javaVersionMap;
//Dont know how
//@Value("#{systemProperties.javav.version}")
//private String javaVersionDirect;
@Value("${java.version}")
private String javaVersionProp;
//-DcmdParam=helloWorld
@Value("#{systemProperties['cmdParam']}")
private String cmdParamMap;
@Value("#{systemProperties.cmdParam}")
private String cmdParamDirect;
@Value("${cmdParam}")
private String cmdParamProp
您可以在 @Value
注释或config.xml文件(< property name =databaseName值)中使用所有这些注释=#{systemProperties.databaseName}/>
)
You can use all of them in a @Value
annotation or the config.xml files (<property name="databaseName" value="#{systemProperties.databaseName}"/>
)
这篇关于是否有任何语法:#{systemProperties ['environment_variable_name']}来获取系统变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!