user1120144
user1120144

Reputation:

How to read jBoss configuration files in Spring?

I want to have a project independent configuration file that I can access from different projects. What I'm currently trying (and does not give me good results at all):

<bean id="wroProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">  
<property name="location" value="${JBOSS_HOME}/standalone/configuration/wro.properties" />  
</bean>

I use Spring 3 and JBoss 7.1. My configuration files are under jboss/standalone/configuration/....properties. Besides that I want to read message files from that same directory with:

<bean id="messageSource"
    class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basenames" value="messages,local" />
    <property name="useCodeAsDefaultMessage" value="true" />
</bean>

Currently it looks for messages.properties and local.properties in src folder?

Upvotes: 0

Views: 4056

Answers (2)

user1120144
user1120144

Reputation:

This is the solution I ended up using, which is platform independent and portable:

<bean id="wroProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="location" value="file:#{systemProperties['jboss.home.dir']}/standalone/configuration/wro.properties" />  
</bean>

The configuration of the message source is identical.

Upvotes: 2

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 279930

A ResourceBundleMessageSource uses the basenames provided to (and the locale) to build a resource name (ex. message.properties) which is eventually (in the call stack) used by java.util.ResourceBundle.Control#newBundle(...). This resource name is then looked for on the classpath starting at its root (ex. /message.properties).

If you're on an IDE like Eclipse, your classpath very likely starts at src.

If jboss/standalone/configuration/... is on your classpath as well and the properties file are in there, you can change the basenames to

<bean id="messageSource"
    class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basenames" value="jboss/standalone/configuration/messages,jboss/standalone/configuration/local" />
    <property name="useCodeAsDefaultMessage" value="true" />
</bean>

Upvotes: 0

Related Questions