0

How can I pass vm args (java -Dport = 5) to the application context?

I want to configure the port dynamically by the user, using the application context.

Sarit
  • 101
  • 1
  • 3
  • 6

2 Answers2

2

In case you trying to access the VM arguments in spring application context, then just add the below bean definition in context file:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
  <property name="ignoreUnresolvablePlaceholders" value="true"></property>
</bean> 

And access the VM args as ${vm_property}.

e.g if you passed the –Dport=5, which can be accessed as

<bean class="com.testing.test.MyClass">  
  <property name="myProperty" value="${port}"></property>  
</bean>
Nikhil A A
  • 441
  • 1
  • 4
  • 17
0

I think There is only one way in spring using injection. and get the property value from any property file