1

I have a web application deployed on Tomcat server. I have the following bean hiveDataSource created in my application-context.xml:

<!-- Hive Data Source for Connection Pooling -->
    <bean id="hiveDataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="url" value="jdbc:hive2://localhost:10000/demo48" />
        <property name="driverClassName" value="org.apache.hive.jdbc.HiveDriver" />
        <property name="username" value="hive" />
        <property name="password" value="" />
        <property name="removeAbandoned" value="true" />
        <property name="initialSize" value="5" />
        <property name="maxActive" value="20" />
    </bean>

I want to change the value of property URL, username and password at run time for bean hiveDataSource. Is there any way to change these property values at runtime?

kryger
  • 12,906
  • 8
  • 44
  • 65
Reena Upadhyay
  • 1,977
  • 20
  • 35
  • http://stackoverflow.com/questions/4041300/can-i-replace-a-spring-bean-definition-at-runtime might answer your question – Jeremy W Nov 25 '14 at 16:38

1 Answers1

0

The documentation says that these fields have protected access, so you wont be able to change their values.
Even if you do, by using reflection or in some other way, it's not likely that data source would just pick up these new values. It would probably have to be restarted or reinitialized in some way.

Predrag Maric
  • 23,938
  • 5
  • 52
  • 68
  • One more Question: if I have a bean defined for some user defined class, and it has public properties, SO how can I change the property values for that particular bean at run time? – Reena Upadhyay Nov 25 '14 at 17:04
  • @Upadhyay You can get the bean from spring context, and change its field values, something like this `MyClass myClass = applicationContext.getBean("myClass")` – Predrag Maric Nov 25 '14 at 17:19