I have an application which needs to run twice with different port numbers, is there a way that I can pass the port number as command line arguments and retrieve them in the spring context file.
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL">
<value>vm://localhost:${<i>port number goes here</i>}</value>
</property>
</bean>
If it is a passed is as a system property, you can do that. Add a -Dport.number=8080 (or whatever port you want) to the JVM command and then change the property value to this :
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL">
<value>vm://localhost:${port.number}/value>
</property>
</bean>
ie.
java -Dport.number=8080 com.package.MyMain
if you dont have any problem with using Static variables this is what you can use..
public class MyClass{
public static String[] ARGS;
public static void main(String[] args) {
ARGS = args;
}
}
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL">
<value>#{'vm://localhost:'+argsportnumber}</value>
</property>
</bean>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With