• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Dynamic bean.xml in Spring Framework  RSS feed

 
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.
 
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".
 
ranger
Posts: 17314
11
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
Boost this thread!