From 8291c801229786cc6cd50f585e81021cd0ec1a72 Mon Sep 17 00:00:00 2001 From: Costin Leau <cleau@vmware.com> Date: Thu, 26 Nov 2009 16:47:32 +0000 Subject: [PATCH] SPR-6447 + added on the fly db configuration to all contexts + removed schema numbers to always pick the latest version --- .../WEB-INF/applicationContext-hibernate.xml | 18 ++++++++---- .../WEB-INF/applicationContext-jdbc.xml | 16 +++++++---- .../webapp/WEB-INF/applicationContext-jpa.xml | 28 +++++++++++++------ src/main/webapp/WEB-INF/petclinic-servlet.xml | 4 +-- 4 files changed, 45 insertions(+), 21 deletions(-) diff --git a/src/main/webapp/WEB-INF/applicationContext-hibernate.xml b/src/main/webapp/WEB-INF/applicationContext-hibernate.xml index bfc166d..39a939a 100644 --- a/src/main/webapp/WEB-INF/applicationContext-hibernate.xml +++ b/src/main/webapp/WEB-INF/applicationContext-hibernate.xml @@ -6,10 +6,10 @@ xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" - http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd - http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd - http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd - http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd + http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd + http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- ========================= RESOURCE DEFINITIONS ========================= --> @@ -22,10 +22,18 @@ for the required JAR files. Alternatively you can use another connection pool such as C3P0, similarly configured using Spring. --> + + <bean id="dataSource" class="org.springframework.samples.petclinic.config.DbcpDataSourceFactory" + p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}" + p:username="${jdbc.username}" p:password="${jdbc.password}" p:populate="${jdbc.populate}" + p:schemaLocation="${jdbc.schemaLocation}" p:dataLocation="${jdbc.dataLocation}"/> + + <!-- DataSource configuration for Apache Commons DBCP. --> + <!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}" p:username="${jdbc.username}" p:password="${jdbc.password}"/> - + --> <!-- JNDI DataSource for JEE environments --> <!-- <jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/petclinic"/> diff --git a/src/main/webapp/WEB-INF/applicationContext-jdbc.xml b/src/main/webapp/WEB-INF/applicationContext-jdbc.xml index 69a2b1f..e2b9bb4 100644 --- a/src/main/webapp/WEB-INF/applicationContext-jdbc.xml +++ b/src/main/webapp/WEB-INF/applicationContext-jdbc.xml @@ -7,11 +7,11 @@ xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" - http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd - http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd - http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd - http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd - http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> + http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd + http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd + http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- ========================= RESOURCE DEFINITIONS ========================= --> @@ -32,6 +32,12 @@ p:username="${jdbc.username}" p:password="${jdbc.password}" p:populate="${jdbc.populate}" p:schemaLocation="${jdbc.schemaLocation}" p:dataLocation="${jdbc.dataLocation}"/> + <!-- DataSource configuration for Apache Commons DBCP. --> + <!-- + <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" + p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}" p:username="${jdbc.username}" + p:password="${jdbc.password}"/> + --> <!-- JNDI DataSource for JEE environments --> <!-- <jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/petclinic"/> diff --git a/src/main/webapp/WEB-INF/applicationContext-jpa.xml b/src/main/webapp/WEB-INF/applicationContext-jpa.xml index 25374e9..5b2be5e 100644 --- a/src/main/webapp/WEB-INF/applicationContext-jpa.xml +++ b/src/main/webapp/WEB-INF/applicationContext-jpa.xml @@ -7,11 +7,11 @@ xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" - http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd - http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd - http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd - http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd - http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> + http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd + http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd + http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- ========================= RESOURCE DEFINITIONS ========================= --> @@ -27,14 +27,24 @@ <context:property-placeholder location="classpath:jdbc.properties"/> <!-- - Uses Apache Commons DBCP for connection pooling. See Commons DBCP documentation - for the required JAR files. Alternatively you can use another connection pool - such as C3P0, similarly configured using Spring. + Spring FactoryBean that creates a DataSource using Apache Commons DBCP for connection + pooling. See Commons DBCP documentation for the required JAR files. This factory bean + can populate the data source with a schema and data scripts if configured to do so. + + An alternate factory bean can be created for different connection pool implementations, + C3P0 for example. --> + <bean id="dataSource" class="org.springframework.samples.petclinic.config.DbcpDataSourceFactory" + p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}" + p:username="${jdbc.username}" p:password="${jdbc.password}" p:populate="${jdbc.populate}" + p:schemaLocation="${jdbc.schemaLocation}" p:dataLocation="${jdbc.dataLocation}"/> + + <!-- DataSource configuration for Apache Commons DBCP. --> + <!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}" p:username="${jdbc.username}" p:password="${jdbc.password}"/> - + --> <!-- JNDI DataSource for JEE environments --> <!-- <jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/petclinic"/> diff --git a/src/main/webapp/WEB-INF/petclinic-servlet.xml b/src/main/webapp/WEB-INF/petclinic-servlet.xml index 3c05fc3..e55766a 100644 --- a/src/main/webapp/WEB-INF/petclinic-servlet.xml +++ b/src/main/webapp/WEB-INF/petclinic-servlet.xml @@ -5,8 +5,8 @@ <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:oxm="http://www.springframework.org/schema/oxm" - xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd - http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd"> <!-- -- GitLab