Tuesday, December 16, 2008

Spring - JBoss Application Properties Integration - 1

Even though there have been so many things written about Spring and JBoss it seems that there really isn't a good discussion around properties. I have been doing web development with JBoss since 2003 and have found that the properties service is invaluable to work with since it really makes it easy to deal with Server based properties that are bound to the system that it is running on.






<mbean code="org.jboss.varia.property.SystemPropertiesService"
name="jboss:type=Service,name=SystemProperties">

<attribute name="Properties">
project.filepath=../soap/project.xml
project.service=service
project.portNumber=8888
</attribute>

</mbean>

</server>

If you are curious about the Properties service, there is a properties-service.xml in each deploy directory of your JBoss implementation. This file, if not changed by the user does not contain any properties. When there are properties added to the file they become "Java System properties." The properties are then available to Springs' PropertyPlaceholderConfigurer.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesMode" value="2"></property>
<property name="location" value="WEB-INF/test.properties"/>
</bean>
<bean id="soapUi" class="com.test.utility.SpringMockServiceRunner" lazy-init="false">
<constructor-arg index="0" value="${project.filepath}" />
<constructor-arg index="2" value="${project.portNumber}"/>
<constructor-arg index="1" value="${project.service}"/>
</bean>
</beans>

More on different options available next time..

0 comments: