Property Priority: system file and descriptor file versus property file

If I have a system property that I pass to my container (e.g. Tomcat) as follows:

-Dmy.property=myValueOne

and a property with the same key defined in my web.xml:

  <context-param>
    <param-name>my.property</param-name>
    <param-value>myValueTwo</param-value>
  </context-param>

... and a property with the same key defined in one of the config * .properties files:

my.property=myValueThree

What value will this property have? myValueOne, myValueTwoor myValueThree?

If you have several properties with the same key, is there a hierarchy that defines which type of property overwrites another type of property?

+4
source share
1 answer

, , SpEL .

#{systemProperties['my.property']} // myValueOne
#{servletContextInitParams['my.property'] // myValueTwo

, (a @PropertySource `

, , , , , , .

<property name="myProperty" value="${my.property}" />

, ( Spring 3.1 ), -.

  • ParalleConfig Init Params (
  • ParalleContext Init Params
  • JNDI
  • ( -D)

, ${my.property} myValueThree. , . local-override="true", , myValueTwo.

  • StandardServletEnvironment javadoc
  • StandardEnvironment javadoc
  • PropertySourcesPlaceholderConfigurer javadoc
+4

Source: https://habr.com/ru/post/1530949/


All Articles