|
From: <jue...@we...> - 2003-05-27 18:28:25
|
On an occasion, some examples for setting up a DataSource in a Spring = ApplicationContext. All of them can be passed to the dataSource property = of DataSourceTransactionManager, JdbcTemplate, or custom beans as bean = reference. Switching between them is thus a matter of configuration - = just activate the respective bean definition. A mock DataSource that wraps a single connection (mainly for test = suites): <bean name=3D"dataSource" = class=3D"com.interface21.jdbc.datasource.SingleConnectionDataSource"> <property name=3D"suppressClose">true</property> <property name=3D"driverName">com.mysql.jdbc.Driver</property> <property name=3D"url">jdbc:mysql://localhost:3306/cbx</property> <property name=3D"user">root</property> </bean> A mock DataSource that creates a new connection on every getConnection = call: <bean name=3D"dataSource" = class=3D"com.interface21.jdbc.datasource.DriverManagerDataSource"> <property name=3D"driverName">com.mysql.jdbc.Driver</property> <property name=3D"url">jdbc:mysql://localhost:3306/cbx</property> <property name=3D"user">root</property> </bean> An example for a pooling Apache Commons DBCP DataSource: <bean name=3D"dataSource" = class=3D"org.apache.commons.dbcp.BasicDataSource"> <property name=3D"driverClassName">com.mysql.jdbc.Driver</property> <property name=3D"url">jdbc:mysql://localhost:3306/cbx</property> <property name=3D"username">root</property> <property name=3D"validationQuery">SELECT * FROM language</property> </bean> The preferred way in a J2EE container - a JNDI DataSource: <bean name=3D"dataSource" = class=3D"com.interface21.jndi.JndiObjectFactoryBean"> <property name=3D"jndiName">jdbc/cbx</property> </bean> DI J=FCrgen H=F6ller Senior System Architect ______________________________________ werk3ATS - division systementwicklung part of werk3AT internetmedien oeg europaplatz 4 A - 4020 linz t. +43 (0) 732 71 65 29 502 f. +43 (0) 732 71 65 29 3 jue...@we... www.werk3at.com ______________________________________ werk3ATS - WIR ENTWICKELN ERFOLG |