diff --git a/README.md b/README.md index 5915bd661d5d034df8590b64192c8b0d03cf943a..21c6d7a93e347e33d3ad0af6fb9b9876105f79bd 100644 --- a/README.md +++ b/README.md @@ -43,21 +43,41 @@ Our issue tracker is available here: https://github.com/spring-petclinic/spring- ## Database configuration -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. +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. +Dependency for Connector/J, the MySQL JDBC driver is already included in the `pom.xml` files. + +### Start a MySql database You may start a MySql database with docker: ``` docker run -e MYSQL_ROOT_PASSWORD=petclinic -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:5.7.8 ``` +or download and install the MySQL database (e.g., MySQL Community Server 5.7 GA), which can be found here: https://dev.mysql.com/downloads/ + +### Use the Spring 'mysql' profile + +To use a MySQL database, you have to start 3 microservices (`visits-service`, `customers-service` and `vets-services`) +with the `mysql` Spring profile. Add the `--spring.profiles.active=mysql` as programm argument. + +By default, at startup, database schema will be created and data will be populated. +You may also manualy create the PetClinic database and data by executing the `"db/mysql/{schema,data}.sql"` scripts of each 3 microservices. +In the `application.yml` of the [Configuration repository], set the `initialization-mode` to `never`. + +If you are running the microservices with Docker, you have to add the `mysql` profile into the (Dockerfile)[docker/Dockerfile]: +``` +ENV SPRING_PROFILES_ACTIVE docker,mysql +``` +In the `mysql section` of the `application.yml` from the [Configuration repository], you have to change +the host and port of your MySQL JDBC connection string. + ## Looking for something in particular? | Spring Cloud components | Resources | |-------------------------|------------| -| Configuration server | [Config server properties](spring-petclinic-config-server/src/main/resources/application.yml) and [Configuration repository](https://github.com/spring-petclinic/spring-petclinic-microservices-config) | +| Configuration server | [Config server properties](spring-petclinic-config-server/src/main/resources/application.yml) and [Configuration repository] | | Service Discovery | [Eureka server](spring-petclinic-discovery-server) and [Service discovery client](spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/VetsServiceApplication.java) | | API Gateway | [Zuul reverse proxy](spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/ApiGatewayApplication.java) and [Routing configuration](https://github.com/spring-petclinic/spring-petclinic-microservices-config/blob/master/api-gateway.yml) | | Docker Compose | [Spring Boot with Docker guide](https://spring.io/guides/gs/spring-boot-docker/) and [docker-compose file](docker-compose.yml) | @@ -78,3 +98,6 @@ docker run -e MYSQL_ROOT_PASSWORD=petclinic -e MYSQL_DATABASE=petclinic -p 3306: The [issue tracker](https://github.com/spring-petclinic/spring-petclinic-microservices/issues) is the preferred channel for bug reports, features requests and submitting pull requests. For pull requests, editor preferences are available in the [editor config](.editorconfig) for easy use in common text editors. Read more and download plugins at <http://editorconfig.org>. + + +[Configuration repository]: https://github.com/spring-petclinic/spring-petclinic-microservices-config diff --git a/db_readme.txt b/db_readme.txt deleted file mode 100644 index 68e3f245c44ae94a260c7456f76497a75864c34a..0000000000000000000000000000000000000000 --- a/db_readme.txt +++ /dev/null @@ -1,13 +0,0 @@ -================================================================================ -=== Spring PetClinic sample application - Database Configuration === -================================================================================ - -@author Costin Leau - --------------------------------------------------------------------------------- - -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. diff --git a/petclinic_db_setup_mysql.txt b/petclinic_db_setup_mysql.txt deleted file mode 100644 index 765711ea9c07dee118a8625a9f5e1c7f921b7902..0000000000000000000000000000000000000000 --- a/petclinic_db_setup_mysql.txt +++ /dev/null @@ -1,24 +0,0 @@ -================================================================================ -=== Spring PetClinic sample application - MySQL Configuration === -================================================================================ - -@author Sam Brannen -@author Costin Leau - --------------------------------------------------------------------------------- - -1) Download and install the MySQL database (e.g., MySQL Community Server 5.1.x), - which can be found here: http://dev.mysql.com/downloads/ - -2) Download Connector/J, the MySQL JDBC driver (e.g., Connector/J 5.1.x), which - can be found here: http://dev.mysql.com/downloads/connector/j/ - Copy the Connector/J JAR file (e.g., mysql-connector-java-5.1.5-bin.jar) into - the db/mysql directory. Alternatively, uncomment the mysql-connector from the - Petclinic pom. - -3) Create the PetClinic database and user by executing the "db/mysql/createDB.txt" - script. - -4) Open "src/main/resources/spring/data-access.properties"; comment out all properties in the - "HSQL Settings" section; uncomment all properties in the "MySQL Settings" - section. diff --git a/spring-petclinic-customers-service/src/main/resources/application.properties b/spring-petclinic-customers-service/src/main/resources/application.properties index 00b397d0063f8be4d37549f6861498ce7a71068d..e6bce2ebe77a2d478844eae0bfd9287b75fbbf51 100644 --- a/spring-petclinic-customers-service/src/main/resources/application.properties +++ b/spring-petclinic-customers-service/src/main/resources/application.properties @@ -1,5 +1,2 @@ server.port=0 -petclinic.database=hsqldb -spring.datasource.schema=classpath*:db/${petclinic.database}/schema.sql -spring.datasource.data=classpath*:db/${petclinic.database}/data.sql logging.level.org.springframework=INFO diff --git a/spring-petclinic-customers-service/src/main/resources/db/mysql/data.sql b/spring-petclinic-customers-service/src/main/resources/db/mysql/data.sql index cbc917a446af3c6caf36d574df984521ac84e7e4..d6e91b1b34d21d8d60e9365851575296d4398945 100644 --- a/spring-petclinic-customers-service/src/main/resources/db/mysql/data.sql +++ b/spring-petclinic-customers-service/src/main/resources/db/mysql/data.sql @@ -29,8 +29,3 @@ INSERT IGNORE INTO pets VALUES (10, 'Mulligan', '1997-02-24', 2, 8); INSERT IGNORE INTO pets VALUES (11, 'Freddy', '2000-03-09', 5, 9); INSERT IGNORE INTO pets VALUES (12, 'Lucky', '2000-06-24', 2, 10); INSERT IGNORE INTO pets VALUES (13, 'Sly', '2002-06-08', 1, 10); - -INSERT IGNORE INTO visits VALUES (1, 7, '2010-03-04', 'rabies shot'); -INSERT IGNORE INTO visits VALUES (2, 8, '2011-03-04', 'rabies shot'); -INSERT IGNORE INTO visits VALUES (3, 8, '2009-06-04', 'neutered'); -INSERT IGNORE INTO visits VALUES (4, 7, '2008-09-04', 'spayed'); diff --git a/spring-petclinic-customers-service/src/test/resources/application-test.yml b/spring-petclinic-customers-service/src/test/resources/application-test.yml index 0a71b59e9aa69c73a5c55b361972b24a81018fde..0abdac4430a050564a12ae2e1da8dc9526928f9a 100644 --- a/spring-petclinic-customers-service/src/test/resources/application-test.yml +++ b/spring-petclinic-customers-service/src/test/resources/application-test.yml @@ -1,4 +1,9 @@ spring.jpa.hibernate.ddl-auto: none +spring: + datasource: + schema: classpath*:db/hsqldb/schema.sql + data: classpath*:db/hsqldb/data.sql + logging.level.org.springframework: INFO diff --git a/spring-petclinic-vets-service/src/main/resources/application.properties b/spring-petclinic-vets-service/src/main/resources/application.properties index 52d0b2a2102001c732bb1dbb115ea62b6dce1cfd..50072a6e8909edff924c63b61917cc2731702f5a 100644 --- a/spring-petclinic-vets-service/src/main/resources/application.properties +++ b/spring-petclinic-vets-service/src/main/resources/application.properties @@ -1,7 +1,3 @@ server.port=0 -petclinic.database=hsqldb -spring.datasource.schema=classpath*:db/${petclinic.database}/schema.sql -spring.datasource.data=classpath*:db/${petclinic.database}/data.sql -logging.level.org.springframework=INFO spring.profiles.active=production -spring.cache.cache-names=vets \ No newline at end of file +spring.cache.cache-names=vets diff --git a/spring-petclinic-vets-service/src/test/resources/application-test.yml b/spring-petclinic-vets-service/src/test/resources/application-test.yml index 77d3ecb368690776fd04c4edb4ed74aaea77acd1..2d18cfdeaf9f81f31ac0b2512355389a9ecf4f51 100644 --- a/spring-petclinic-vets-service/src/test/resources/application-test.yml +++ b/spring-petclinic-vets-service/src/test/resources/application-test.yml @@ -1,5 +1,10 @@ spring.jpa.hibernate.ddl-auto: none +spring: + datasource: + schema: classpath*:db/hsqldb/schema.sql + data: classpath*:db/hsqldb/data.sql + vets: cache: ttl: 10 diff --git a/spring-petclinic-visits-service/src/main/resources/application.properties b/spring-petclinic-visits-service/src/main/resources/application.properties index 00b397d0063f8be4d37549f6861498ce7a71068d..cbe617ef036b199654011c74a3b41bf3602440c9 100644 --- a/spring-petclinic-visits-service/src/main/resources/application.properties +++ b/spring-petclinic-visits-service/src/main/resources/application.properties @@ -1,5 +1 @@ server.port=0 -petclinic.database=hsqldb -spring.datasource.schema=classpath*:db/${petclinic.database}/schema.sql -spring.datasource.data=classpath*:db/${petclinic.database}/data.sql -logging.level.org.springframework=INFO diff --git a/spring-petclinic-visits-service/src/test/resources/application-test.yml b/spring-petclinic-visits-service/src/test/resources/application-test.yml index 0a71b59e9aa69c73a5c55b361972b24a81018fde..0abdac4430a050564a12ae2e1da8dc9526928f9a 100644 --- a/spring-petclinic-visits-service/src/test/resources/application-test.yml +++ b/spring-petclinic-visits-service/src/test/resources/application-test.yml @@ -1,4 +1,9 @@ spring.jpa.hibernate.ddl-auto: none +spring: + datasource: + schema: classpath*:db/hsqldb/schema.sql + data: classpath*:db/hsqldb/data.sql + logging.level.org.springframework: INFO