diff --git a/readme.md b/readme.md index e6fb9c7ac2a0cc3534cd453ce68181ecb981315b..43ca93fdfb8cfbfc2b9e5dfd3de4122acb49d9ca 100644 --- a/readme.md +++ b/readme.md @@ -10,7 +10,7 @@ The [spring-petclinic-angular2 project](https://github.com/spring-petclinic/spri ``` git clone https://github.com/spring-petclinic/spring-petclinic-rest.git cd spring-petclinic - ./mvnw tomcat7:run + ./mvnw spring-boot:run ``` You can then access petclinic here: http://localhost:9966/petclinic/ @@ -31,24 +31,25 @@ Our issue tracker is available here: https://github.com/spring-petclinic/spring- In its default configuration, Petclinic uses an in-memory database (HSQLDB) which gets populated at startup with data. A similar setups is provided for MySql and PostgreSQL in case a persistent database configuration is needed. -To run petclinic locally using persistent database, it is needed to run with profile defined in main pom.xml file. - -For MySQL database, it is needed to run with 'MySQL' profile defined in main pom.xml file. +To run petclinic locally using persistent database, it is needed to change profile defined in application.properties file. +For MySQL database, it is needed to change param "hsqldb" to "mysql" in string ``` - ./mvnw tomcat7:run -P MySQL +spring.profiles.active=hsqldb,spring-data-jpa ``` + defined in application.properties file. -Before do this, would be good to check properties defined in MySQL profile inside pom.xml file. +Before do this, would be good to check properties defined in application-mysql.properties file. ``` - <properties> - <jpa.database>MYSQL</jpa.database> - <jdbc.driverClassName>com.mysql.jdbc.Driver</jdbc.driverClassName> - <jdbc.url>jdbc:mysql://localhost:3306/petclinic?useUnicode=true</jdbc.url> - <jdbc.username>root</jdbc.username> - <jdbc.password>petclinic</jdbc.password> - </properties> +spring.datasource.url = jdbc:mysql://localhost:3306/petclinic?useUnicode=true +spring.datasource.driverClassName = com.mysql.jdbc.Driver +spring.datasource.username=root +spring.datasource.password=petclinic +spring.datasource.driver-class-name=com.mysql.jdbc.Driver +spring.jpa.database=MYSQL +spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect +spring.jpa.hibernate.ddl-auto=none ``` You may also start a MySql database with docker: @@ -57,22 +58,23 @@ You may also start a MySql database with docker: docker run --name mysql-petclinic -e MYSQL_ROOT_PASSWORD=petclinic -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:5.7.8 ``` -For PostgreSQL database, it is needed to run with 'PostgreSQL' profile defined in main pom.xml file. - +For PostgeSQL database, it is needed to change param "hsqldb" to "postgresql" in string ``` - ./mvnw tomcat7:run -P PostgreSQL +spring.profiles.active=hsqldb,spring-data-jpa ``` + defined in applcation.properties file. -Before do this, would be good to check properties defined in PostgreSQL profile inside pom.xml file. +Before do this, would be good to check properties defined in application-postgresql.properties file. ``` - <properties> - <jpa.database>POSTGRESQL</jpa.database> - <jdbc.driverClassName>org.postgresql.Driver</jdbc.driverClassName> - <jdbc.url>jdbc:postgresql://localhost:5432/petclinic</jdbc.url> - <jdbc.username>postgres</jdbc.username> - <jdbc.password>petclinic</jdbc.password> - </properties> +spring.datasource.url=jdbc:postgresql://localhost:5432/petclinic +spring.datasource.driverClassName=org.postgresql.Driver +spring.datasource.username=postgres +spring.datasource.password=petclinic +spring.datasource.driver-class-name=org.postgresql.Driver +spring.jpa.database=POSTGRESQL +spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect +spring.jpa.hibernate.ddl-auto=none ``` You may also start a Postgres database with docker: diff --git a/src/main/resources/application-mysql.properties b/src/main/resources/application-mysql.properties index cfadd6ef08c7ffe11eb4911b51561c9747c34ba3..c3de1eec76e8500b5d58e81d7251fa4d1d461a00 100644 --- a/src/main/resources/application-mysql.properties +++ b/src/main/resources/application-mysql.properties @@ -1,4 +1,5 @@ # uncomment for init database (first start) +#spring.datasource.initialize=true #spring.datasource.schema=classpath*:db/mysql/initDB.sql #spring.datasource.data=classpath*:db/mysql/populateDB.sql diff --git a/src/main/resources/application-postgresql.properties b/src/main/resources/application-postgresql.properties index b9aa1a2eb1c6419cec31d5a13dc8855fda340199..a5001c6734eeb8200fc6c14e2f92dd0072fdc4d0 100644 --- a/src/main/resources/application-postgresql.properties +++ b/src/main/resources/application-postgresql.properties @@ -1,4 +1,5 @@ # uncomment for init database (first start) +#spring.datasource.initialize=true #spring.datasource.schema=classpath*:db/postgresql/initDB.sql #spring.datasource.data=classpath*:db/postgresql/populateDB.sql diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 4304e983dc40f41226c3dfd925d90c3c36ad6bd3..5458cbee9dfac91ee96c7684b7fa9c39cc61ee51 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -16,7 +16,7 @@ # When using Spring Data JPA, use: spring-data-jpa # ------------------------------------------------ -spring.profiles.active=hsqldb,jdbc +spring.profiles.active=hsqldb,spring-data-jpa # ------------------------------------------------ diff --git a/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt b/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt index 2e430e02b37afef37e5e1b09c01762203fe22e03..49aa57e74739b073765dbedd613c89768c5c2d03 100644 --- a/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt +++ b/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt @@ -12,12 +12,9 @@ Alternatively, you may use the official MySQL docker image. Refer to the README.md for the Docker command line. -2) Dependency for Connector/J, the MySQL JDBC driver (e.g., Connector/J 5.1.x) is - included in Petclinic pom.xml file. See the MySQL maven profile. - Alternatively, download Connector/J JDBC driver from here: - http://dev.mysql.com/downloads/connector/j/ - and copy the MySQL JDBC driver JAR file (e.g., mysql-connector-java-5.1.5-bin.jar). -3) Change connection parameters into the MySQL profile of the pom.xml. - Build and starth the web app with the MySQL profile: - ./mvnw tomcat7:run -P MySQL +2) Create the PetClinic database and user by executing the "db/mysql/initDB.sql" +and "db/mysql/populateDB.sql" scripts. Or uncomment strings +#spring.datasource.schema=classpath*:db/mysql/initDB.sql +#spring.datasource.data=classpath*:db/mysql/populateDB.sql + in application-mysql.properties file at the first time you run the app. \ No newline at end of file diff --git a/src/main/resources/db/postgresql/petclinic_db_setup_postgresql.txt b/src/main/resources/db/postgresql/petclinic_db_setup_postgresql.txt index 6d450b7ad132f724afc547d482495d522349dc9f..e07e1ecc718c3a167a5e6ebd5e178761e098dec5 100644 --- a/src/main/resources/db/postgresql/petclinic_db_setup_postgresql.txt +++ b/src/main/resources/db/postgresql/petclinic_db_setup_postgresql.txt @@ -2,21 +2,16 @@ === Spring PetClinic sample application - PostgreSQL Configuration === ================================================================================ -@author Sam Brannen -@author Costin Leau +@author Vitaliy Fedoriv +@autor Antoine Rey -------------------------------------------------------------------------------- 1) Download and install the PostgreSQL database, which can be found here: https://www.postgresql.org/download/ -2) Dependency for postgresql-driver included in Petclinic pom.xml file. - See the PostgreSQL maven profile. - Alternatively, download PostgreSQL JDBC driver from here: https://jdbc.postgresql.org/download.html - and copy the PostgreSQL JDBC driver JAR file (e.g., postgresql-9.4.1211.jre7.jar) into - the db/postgesql directory. -3) Open psql and create the PetClinic database: +2) Open psql and create the PetClinic database: CREATE DATABASE petclinic WITH OWNER = postgres @@ -24,6 +19,9 @@ TABLESPACE = pg_default CONNECTION LIMIT = -1; -4) If required, change connection parameters into the PostgreSQL profile of the pom.xml. - Build and starth the web app with the PostgreSQL profile: - ./mvnw tomcat7:run -P PostgreSQL +3) Create the PetClinic tables by executing the "db/postgresql/initDB.sql". +Then execute "db/mysql/populateDB.sql" script. +Or uncomment strings +#spring.datasource.schema=classpath*:db/postgresql/initDB.sql +#spring.datasource.data=classpath*:db/postgresql/populateDB.sql + in application-postgresql.properties file at the first time you run the app. \ No newline at end of file