• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dynamic bean.xml in Spring Framework

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic