Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I access a property via the ApplicationContext
    text
    copied!<p>When a properties file is used in a Spring ApplicationContext, its properties may be accessed in this manner: ${someproperty} inside your xml configuration files. But how do you access the same property within your java code without injecting it via xml?</p> <p><i>ApplicationContext config</i></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt; &lt;bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;property name="location" value="myapp.properties" /&gt; &lt;/bean&gt; &lt;bean class="my.app.MyClass"&gt; &lt;property name="foo" value="${someproperty}" /&gt; &lt;/bean&gt; &lt;/beans&gt;</code></pre> <p><i>Properties</i></p> <pre><code>someproperty=somevalue</code></pre> <p><b>Update 1</b> <br /> The actual point of this, is a special case where a unique id for the application is set in the properties file (ez editing by sysadmin). Several of the application classes implement ApplicationContextAware so they have access to the context and to prevent injecting in each class or defining a bean for every class we want an ez property access method. Our app "knowing" about Spring is not an issue in this case. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload