Define DataSource bean on code

Posted by Ruben Trancoso on Stack Overflow See other posts from Stack Overflow or by Ruben Trancoso
Published on 2010-03-14T19:35:05Z Indexed on 2010/03/14 20:15 UTC
Read the original article Hit count: 341

Filed under:
|

I would like to make a "First Access Database Setup Process" in my spring application and the only thing I can imagine as a solution would be to initialize the DataSource bean programatically.

My current bean is defined as:

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/catalog" />
    <property name="username" value="condominium" />
    <property name="password" value="password" />
    <property name="validationQuery" value="SELECT 1" />
    <property name="testOnBorrow" value="true" />
    <property name="defaultAutoCommit" value="false" />
    <property name="maxWait" value="5000" />
</bean>

but the ideal thing was to load it by myself in whenever I need it and with the parameter I define.

The scenario is that the user (administrator) comes to the application at the first time and I ask him the server, port and catalog to connect. I store it in a embeeded db and next time application start, a bean can check if the parameter are set on the embedded db and load it again.

Is it possible?

© Stack Overflow or respective owner

Related posts about spring

Related posts about datasource