Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamic bean.xml in Spring Framework

 
tusharlondhe londheAdmin
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I have a bean.xml

<bean id="User" class="com.module.spring.basic.User">
<property name="userName">
<value>ABCD</value>
</property>
</bean>

Now how to make this bean.xml dynamic so that I can pass user provided values.
 
Bhagat Singh Rawat
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tusharlondhe londheAdmin wrote:Hi Guys,

I have a bean.xml

<bean id="User" class="com.module.spring.basic.User">
<property name="userName">
<value>ABCD</value>
</property>
</bean>

Now how to make this bean.xml dynamic so that I can pass user provided values.



Once you get the bean instance by using ctx.getBean("User"), then you can set dynamic name value as userBean.setUserName("User_New_Name") before using the hard coded name "ABCD".
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And I would only set the property in the xml, only if I wanted a default value, and even then if it isn't deploy specific, then I would put the default value in my code.

Anyway, just because you set a property in configuration doesn't mean that you can never call the setter method yourself in code once you get a reference to it.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic