I have code like this, then how to change configure file spring.ctx.xml
so that i can to configure at runtime?
i want change value of this line only, while program is running
p:driverClassName="com.mysql.jdbc.Driver"
p:url="jdbc:mysql://localhost/hibernate2"
p:username="root"
p:password=""
thanks.
file spring.ctx.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="com.mysql.jdbc.Driver"
p:url="jdbc:mysql://localhost/hibernate2"
p:username="root"
p:password="" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
p:dataSource-ref="dataSource">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
${hibernate.dialect}
</prop>
<prop key="hibernate.show_sql">
${hibernate.show_sql}
</prop>
<prop key="hibernate.generate_statistics">
${hibernate.show_statistics}
</prop>
<!-- ini harus diremark agar tablenya digenerate -->
<prop key="hibernate.hbm2ddl.auto">
${hibernate.hbm2ddl_auto}
</prop>
</props>
</property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory" />
</beans>
MainFram.class
Code:
private static ApplicationContext applicationContext;
..
..
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainFrame().setVisible(true);
applicationContext = new ClassPathXmlApplicationContext("spring.ctx.xml");
}
});
}