1) Define the properties beans in spring xml file (typically ApplicationConfiguration.xml file)
as follows:
<!-- Apache Commons Configuration Composite configuration -->2) Define a bean with the getter and setter that returns/accepts an array of org.apache.commons.configuration.Configuration class. To make it easier for the rest of the code to get the configuration easy, you may want to add a utility method in there to return the combined Configutaion. Here is an example:
<bean id="configurations"
class="org.springmodules.commons.configuration.CommonsConfigurationFactoryBean">
<property name="configurations">
<list>
<bean class="org.apache.commons.configuration.PropertiesConfiguration">
<constructor-arg type="java.net.URL"
value="classpath:myconfiguration.properties" />
<property name="reloadingStrategy">
<bean class="org.apache.commons.configuration.reloading.FileChangedReloadingStrategy"/>
</property>
</bean>
<bean class="org.apache.commons.configuration.SystemConfiguration"/>
</list>
</property>
<!-- define configuration as a set of spring resources -->
</bean>
<bean id="configuration" class="org.apache.commons.configuration.Configuration" factory-bean="&configurations" factory-method="getConfigurations"/>
private Configuration configs[] ;3) Define the bean properties in the spring xml file. I suggest, that you may want to define the above method in a base class of all your beans and define it as an abstract bean. This will enable you to use the properties in all your beans without having to define the properties in every bean. Here is an example:
private ConfigurationBuilder cfgBuilder ;
public Configuration[] getConfigs() {
return configs;
}
public void setConfigs(Configuration[] configs) {
this.configs = configs;
cfgBuilder = new ConfigurationBuilder();
for (Configuration cgf: configs) {
cfgBuilder.addConfiguration(cgf);
}
}
public Configuration getConfig() {
return cfgBuilder.getConfiguration();
}
<bean id="baseActionBean" class="com.my.company.BaseAction" abstract="true" >4) Add the necessary libraries if you do not have them already. Here is the list of jars you will need.
<property name="configs" ref="configuration" />
</bean>
<bean id="logonClass" class="com.my.company.UsefulAction" parent="baseActionBean">
</bean>
commons-lang-*.jarWith these changes, you should be able to use the properties in your beans with a code as simple as getConfig().getString("propertyKey")
commons-configuration*.jar
spring-modules-jakarta-commons*.jar
3 comments:
I was shocked to see with Logo Design Company UK that it is not simple to integrate the spring framework with the apache house of common setup.
I was shocked to see that it is not simple to integrate the spring framework with the apache commons setup. I had hoped that the spring framework or the apache commons framework would come with one bean that we could utilize best massage services in Karachi right away, set that as a property in the bean, and continue working with it.
When using Spring Apache Commons for configuration management, it is critical to include describe the main points of health and safety policies and procedures. in your framework. These rules should explicitly specify risk assessments, emergency procedures, and frequent safety audits to ensure a safe atmosphere. It is also critical to create systems for reporting hazards and complying with legal safety regulations.
Post a Comment