From fcf1415a8952ae2c970cd32b5bc1a85988b6af27 Mon Sep 17 00:00:00 2001 From: Mariusz Borwin Date: Mon, 19 Sep 2016 14:57:19 +0200 Subject: [PATCH] Make easier switch between MySQL and HSQLDB #184 Signed-off-by: Mariusz Borwin --- pom.xml | 44 ++++++++++++++++--- readme.md | 18 +++++++- .../resources/spring/data-access.properties | 25 +++-------- 3 files changed, 59 insertions(+), 28 deletions(-) diff --git a/pom.xml b/pom.xml index eaa52cd9d..d654fe8fb 100644 --- a/pom.xml +++ b/pom.xml @@ -41,6 +41,12 @@ 2.7 + HSQL + org.hsqldb.jdbcDriver + jdbc:hsqldb:mem:petclinic + sa + + @@ -185,13 +191,6 @@ runtime - - - org.hibernate @@ -273,6 +272,12 @@ install petclinic + + + ${basedir}/src/main/resources + true + + @@ -377,6 +382,14 @@ + + + org.apache.maven.plugins + maven-resources-plugin + + UTF-8 + + @@ -451,6 +464,23 @@ + + MYSQL + + MYSQL + com.mysql.jdbc.Driver + jdbc:mysql://localhost:3306/petclinic?useUnicode=true + root + petclinic + + + + mysql + mysql-connector-java + ${mysql-driver.version} + + + demopetclinic diff --git a/readme.md b/readme.md index 4b6a0f4cd..e7ea14156 100644 --- a/readme.md +++ b/readme.md @@ -20,7 +20,23 @@ Our issue tracker is available here: https://github.com/spring-projects/spring-p In its default configuration, Petclinic uses an in-memory database (HSQLDB) which gets populated at startup with data. A similar setup is provided for MySql in case a persistent database configuration is needed. -Note that whenever the database type is changed, the data-access.properties file needs to be updated and the mysql-connector-java artifact from the pom.xml needs to be uncommented. +To run petclinic locally using MySQL database, it is needed to run with 'MYSQL' profile defined in main pom.xml file. + +``` + ./mvnw tomcat7:run -P MYSQL +``` + +Before do this, would be good to check properties defined in MYSQL profile inside pom.xml file. + +``` + + MYSQL + com.mysql.jdbc.Driver + jdbc:mysql://localhost:3306/petclinic?useUnicode=true + root + petclinic + +``` You may start a MySql database with docker: diff --git a/src/main/resources/spring/data-access.properties b/src/main/resources/spring/data-access.properties index 567f726a4..b6059028c 100644 --- a/src/main/resources/spring/data-access.properties +++ b/src/main/resources/spring/data-access.properties @@ -10,25 +10,10 @@ jdbc.dataLocation=classpath:db/hsqldb/populateDB.sql jpa.showSql=true -#------------------------------------------------------------------------------- -# HSQL Settings - -jdbc.driverClassName=org.hsqldb.jdbcDriver -jdbc.url=jdbc:hsqldb:mem:petclinic -jdbc.username=sa -jdbc.password= +jdbc.driverClassName=${jdbc.driverClassName} +jdbc.url=${jdbc.url} +jdbc.username=${jdbc.username} +jdbc.password=${jdbc.password} # Property that determines which database to use with an AbstractJpaVendorAdapter -jpa.database=HSQL - - -#------------------------------------------------------------------------------- -# MySQL Settings - -#jdbc.driverClassName=com.mysql.jdbc.Driver -#jdbc.url=jdbc:mysql://localhost:3306/petclinic?useUnicode=true&characterEncoding=UTF-8 -#jdbc.username=root -#jdbc.password=petclinic - -# Property that determines which database to use with an AbstractJpaVendorAdapter -#jpa.database=MYSQL +jpa.database=${jpa.database}