Config BasicDataSource : BasicDataSource « Spring « Java Tutorial






File: context.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>


  <bean id="matchDao"
        class="JdbcMatchDao">
    <property name="dataSource" ref="dataSource"/>
  </bean>

  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
    <property name="url" value="jdbc:hsqldb:hsql:/localhost/test"/>
    <property name="username" value="sa"/>
    <property name="password" value=""/>
    <property name="initialSize" value="10"/>
    <property name="testOnBorrow" value="true"/>
  </bean>


</beans>

File: Main.java

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

public class Main {

  public static void main(String[] args) throws Exception {

    ConfigurableListableBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource(
        "context.xml"));

   

  }
}
  Download:  Spring-ConfigBasicDataSource.zip( 2,598 k)








28.19.BasicDataSource
28.19.1.Config BasicDataSource