PDA

View Full Version : About system properties file


da01661
Sep 12th, 2007, 10:41 PM
Dear all,

I would like to define an application level property file like app.properties with content:

pageSize=4
maxPage=10
......

i would like to allow to read this in anywhere of the application (controller + jsp), how should i define this kind of properties file in spring? and where should i put it?

Thank you!

TrevorIngs
Sep 12th, 2007, 11:11 PM
Dear all,

I would like to define an application level property file like app.properties with content:

pageSize=4
maxPage=10
......

i would like to allow to read this in anywhere of the application (controller + jsp), how should i define this kind of properties file in spring? and where should i put it?

Thank you!

There are a number of ways you could do it, but the short and simple way is,


<bean class="org.springframework.beans.factory.config.PropertyP laceholderConfigurer"
<property name="locations">
<list>
<value>classpath:/application.properties</value>
</list>
</property>
</bean>


then inject you properties where needed and publish via reference data.


<property name="pageSize">
<value>${pageSize}</value>
</property>

//referece data
refData.put("pageSize", this.pageSize);

da01661
Sep 12th, 2007, 11:43 PM
.....

//referece data
refData.put("pageSize", this.pageSize);
[/QUOTE]

Sorry, what do you mean by this statement? where should i insert this?

Thank you!

Jörg Heinicke
Sep 13th, 2007, 12:56 AM
The PropertyPlaceholderConfigurer (http://static.springframework.org/spring/docs/2.0.x/reference/beans.html#beans-factory-placeholderconfigurer) goes into your XML config. Every reference to ${propertyname} is then replaced in the XML, so that you can inject it as normal property - and use it everywhere.

Joerg