Reputation: 33
I have to read property file from WildFly which is outside war in wildfly using spring, i tried it using PropertyPlaceholderConfigurer in spring and it is working but there is one issue.
applicationContext.xml
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>file:/C:\wildfly-9.0.2.Final\wildfly-9.0.2.Final\standalone\deployments\/propertyLoader.properties</value>
</property>
</bean>
<bean id="getPropertyBean"
class="com.csc.loadProperty.GetProperty">
<property name="prefixProp" value="${prefix}" />
<property name="suffixProp" value="${suffix}" />
<property name="newProp" value="${new}" />
</bean>
here i am giving absolute path for propertyLoader.properties, but i have to give relative path from the server as the path can be different for different machines. can anyone help me?
Upvotes: 2
Views: 1008
Reputation: 174
If you are using spring 4 , then specify property file path using ${}
@Configuration
@PropertySource("file:${app.home}/app.properties")
public class AppConfig
@Autowired
Environment env;
}
Then set that app.home as system variable at startup. If you run spring application inside some container then set this property in the java startup options or vm arguments.
java -jar -Dapp.home="/home/dev/config" example.jar
Upvotes: 1
Reputation: 160
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>file:# C:/wildfly-9.0.2.Final/wildfly-9.0.2.Final/standalone/deployments/propertyLoader.properties</value>
</property>
</bean>
Upvotes: 0