I have been working with Spring Framework 3.0 for the last couple weeks and have been really impressed. This is my first project with Java. My main problem is that I can't find a way to let the end user manage their own database connection from within the web application. The project I am working on will be installed on the client's computer and they will provide all the connection information. At this point whenever the DataSource is unavailable I get an error I am not sure how to handle:
java.sql.SQLException: Network error IOException: Connection refused
I tried to lazy load the dataSource in the xml configuration, however it was still loaded when application started during the Pre-instantiating singletons phase.
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
lazy-init="true">
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url"
value="${jdbc.urlprefix}://${jdbc.server}:${jdbc.port}/${jdbc.database}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="initialSize" value="2" />
<property name="maxActive" value="5" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
lazy-init="true">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
....
</list>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"
lazy-init="true">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
I am hoping when the database is unavailable or not configured correctly I could just redirect the user to a page not dependent on the database connection so the settings can be managed. I am just not sure how accomplish this when the IoC container is expecting the DataSource to be configured correctly from the start.
Thank you in advance!