I have a standard web app with spring 3 and hibernate framework. I have both applicationContext.xml and hibernate.cfg.xml files with database connection data:
<hibernate-configuration>
<session-factory>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.cglib.use_reflection_optimizer">true</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.release_mode">after_transaction</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/webapp</property>
<property name="hibernate.connection.username">webapp</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.search.autoregister_listeners">false</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
</session-factory>
</hibernate-configuration>
...
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/webapp" />
<property name="username" value="webapp" />
<property name="password" value="password" />
</bean>
Now I need to change this app using a dynamic database name, how to set it runtime on for example in ServletContextListener.contextInitialized?