Hello Spring Team
Currently about the Javadoc for the PropertySourcesPlaceholderConfigurer class, it contains as first paragraph the following:
Specialization of
PlaceholderConfigurerSupport
that resolves${...}
placeholders within bean definition property values and@Value
annotations against the current SpringEnvironment
and its set ofPropertySources
.
I know this class is mandatory to be defined through a @Bean
through a static
method. Of course it if JavaConfig is used and when Spring is prior 4.3
About:
(1) The within bean definition property values part.
Should appear the XML term and a sample snippet code, otherwise is confuse in someway. It because XML is old school and new Spring developers would be more involved with JavaConfig.
(2) The and @Value annotations part
I know it is about the @Value("db.port")
approach. Where db.port
was defined in some .properties
file and it is loaded through @PropertySource({"classpath:/com/.../mysql.properties"})
. I use this approach a lot of times. But ...
(3) The against the current Spring Environment
and its set of PropertySources
parts
It is confuse, because is possible use the env.getProperty("db.port", Integer.class)
sentence. Where env
is declared as an instance variable of Environment
type and annotated with @Autowired
. Now is obvious that env.getProperty("db.port", Integer.class)
is based on Java and again @PropertySource({"classpath:/com/.../mysql.properties"})
is involved, it to refer the db.port
key.
But, is not clear if behind the scenes the PropertySourcesPlaceholderConfigurer
class is mandatory or not for a successful execution of the env.getProperty("db.port", Integer.class)
sentence.
Apply the same logic for the and its set of PropertySources
part
Therefore if can be added 3 snippet codes would be better to complement and improve the current documentation.
Thanks for your understanding
p.d: Consider to indicate in the javadoc if for the correct execution of @Value("#{environment['db.ip']}")
- SpEL with "environment" - the PropertySourcesPlaceholderConfigurer
class is involved or not
Comment From: snicoll
is not clear if behind the scenes the PropertySourcesPlaceholderConfigurer class is mandatory or not for a successful execution of the env.getProperty("db.port", Integer.class) sentence.
I am failing to see the connection. This class "resolves ${...} placeholders within bean definition property values and @Value annotations". It does not state anywhere it configures the environment so that property sources are loaded. If you want to know how the environment is configured this section of the documentation explains everything.
The Javadoc of this class also states:
See ConfigurableEnvironment and related javadocs for details on manipulating environment property sources.
These above should answer your concerns already.