Skip to content

Commit f4739e3

Browse files
Changed DB from mySQL to Postgre as mySQL db expired
1 parent bac8f74 commit f4739e3

7 files changed

+117
-30
lines changed

.factorypath

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/spring-webmvc/5.3.8/spring-webmvc-5.3.8.jar" enabled="true" runInBatchMode="false"/>
5454
<factorypathentry kind="VARJAR" id="M2_REPO/org/springframework/spring-expression/5.3.8/spring-expression-5.3.8.jar" enabled="true" runInBatchMode="false"/>
5555
<factorypathentry kind="VARJAR" id="M2_REPO/mysql/mysql-connector-java/8.0.25/mysql-connector-java-8.0.25.jar" enabled="true" runInBatchMode="false"/>
56+
<factorypathentry kind="VARJAR" id="M2_REPO/org/postgresql/postgresql/42.2.22/postgresql-42.2.22.jar" enabled="true" runInBatchMode="false"/>
57+
<factorypathentry kind="VARJAR" id="M2_REPO/org/checkerframework/checker-qual/3.5.0/checker-qual-3.5.0.jar" enabled="true" runInBatchMode="false"/>
5658
<factorypathentry kind="VARJAR" id="M2_REPO/org/projectlombok/lombok/1.18.20/lombok-1.18.20.jar" enabled="true" runInBatchMode="false"/>
5759
<factorypathentry kind="VARJAR" id="M2_REPO/io/springfox/springfox-swagger2/2.9.2/springfox-swagger2-2.9.2.jar" enabled="true" runInBatchMode="false"/>
5860
<factorypathentry kind="VARJAR" id="M2_REPO/io/swagger/swagger-annotations/1.5.20/swagger-annotations-1.5.20.jar" enabled="true" runInBatchMode="false"/>

CourseAPI-Spring-Starter.md

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,37 @@
11
# CourseAPI-Spring-Starter - Tutorial
22

3-
[TOC]
4-
5-
**Prerequisites and Installation**
3+
### Table of contents
4+
5+
- [Prerequisites and Installation](#prerequisites-and-installation)
6+
- [Creating Spring Boot Project](#creating-spring-boot-project)
7+
- [Starting a Spring Boot App](#starting-a-spring-boot-app)
8+
- [Adding a REST Controller](#adding-a-rest-controller)
9+
- [Returning Objects From Controller](#returning-objects-from-controller)
10+
- [Behind the Scenes](#behind-the-scenes)
11+
- [Bill Of Materials](#bill-of-materials)
12+
- [Embedded Servlet Container](#embedded-servlet-container)
13+
- [Spring MVC- The View Tier](#spring-mvc--the-view-tier)
14+
- [Topic API - The 1st REST Api we'll build](#topic-api---the-1st-rest-api-well-build)
15+
- [Creating Business Service](#creating-business-service)
16+
- [Getting a specific Topic](#getting-a-specific-topic)
17+
- [Adding new resource using POST](#adding-new-resource-using-post)
18+
- [Implementing Update using PUT](#implementing-update-using-put)
19+
- [Implementing DELETE using DELETE](#implementing-delete-using-delete)
20+
- [Ways to Start a Spring Boot App](#ways-to-start-a-spring-boot-app)
21+
- [Using application properties](#using-application-properties)
22+
- [Spring Data JPA](#spring-data-jpa)
23+
- [Creating a Spring Data JPA Repository](#creating-a-spring-data-jpa-repository)
24+
- [Making CRUD operations with Repository](#making-crud-operations-with-repository)
25+
- [Course APIs - Creation](#course-apis---creation)
26+
- [Adding Entity Relationship and Extending Repository](#adding-entity-relationship-and-extending-repository)
27+
- [Lesson APIs](#lesson-apis)
28+
- [Actuator - Monitoring App](#actuator---monitoring-app)
29+
- [Swagger (Documentation Tool)](#swagger-documentation-tool)
30+
- [Packaging Production Ready App](#packaging-production-ready-app)
31+
32+
33+
34+
### Prerequisites and Installation
635

736
- STS 4
837
- JDK 8 or higher
@@ -981,3 +1010,34 @@ Resources -> Configure Addons -> [**JawsDB MySQL**](https://elements.heroku.com
9811010

9821011

9831012

1013+
1014+
1015+
### Changing DB from MySQL to PostgreSQL
1016+
1017+
***pom.xml***
1018+
1019+
```xml
1020+
<dependency>
1021+
<groupId>org.postgresql</groupId>
1022+
<artifactId>postgresql</artifactId>
1023+
<scope>runtime</scope>
1024+
</dependency>
1025+
```
1026+
1027+
***application.properties***
1028+
1029+
```properties
1030+
spring.jpa.hibernate.ddl-auto:update
1031+
spring.jpa.show-sql: true
1032+
1033+
# Connecting to Postgres Database
1034+
#spring.datasource.url=jdbc:postgresql://host:port/database
1035+
spring.datasource.url=jdbc:postgresql://free-tier12.aws-ap-south-1.cockroachlabs.cloud:26257/swarna-db-200.defaultdb
1036+
spring.datasource.username=swarnadeep
1037+
spring.datasource.password=<my_password>
1038+
spring.datasource.driver-class-name=org.postgresql.Driver
1039+
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
1040+
```
1041+
1042+
1043+

pom.xml

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,34 @@
3636
<artifactId>mysql-connector-java</artifactId>
3737
<scope>runtime</scope>
3838
</dependency>
39+
40+
<dependency>
41+
<groupId>org.postgresql</groupId>
42+
<artifactId>postgresql</artifactId>
43+
<scope>runtime</scope>
44+
</dependency>
45+
3946
<dependency>
4047
<groupId>org.projectlombok</groupId>
4148
<artifactId>lombok</artifactId>
4249
<optional>true</optional>
4350
</dependency>
4451

45-
<!-- Production Grade API Documentaion Tool -->
46-
<dependency>
47-
<groupId>io.springfox</groupId>
48-
<artifactId>springfox-swagger2</artifactId>
49-
<version>2.9.2</version>
50-
</dependency>
51-
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
52-
<dependency>
53-
<groupId>io.springfox</groupId>
54-
<artifactId>springfox-swagger-ui</artifactId>
55-
<version>2.9.2</version>
56-
</dependency>
57-
58-
59-
52+
<!-- Production Grade API Documentation Tool -->
53+
<dependency>
54+
<groupId>io.springfox</groupId>
55+
<artifactId>springfox-swagger2</artifactId>
56+
<version>2.9.2</version>
57+
</dependency>
58+
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
59+
<dependency>
60+
<groupId>io.springfox</groupId>
61+
<artifactId>springfox-swagger-ui</artifactId>
62+
<version>2.9.2</version>
63+
</dependency>
64+
65+
66+
6067
<dependency>
6168
<groupId>org.springframework.boot</groupId>
6269
<artifactId>spring-boot-starter-test</artifactId>

src/main/resources/application.properties

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
server.port=8080
22

3-
#mySQL Database Configurations
3+
#JPA config
44
#update means directly change in db while I run application
55
spring.jpa.hibernate.ddl-auto:update
6-
spring.datasource.url=jdbc:mysql://sql6.freesqldatabase.com:3306/sql6472211
7-
spring.datasource.username=sql6472211
8-
spring.datasource.password=BKZrwMePLL
6+
spring.jpa.show-sql: true
7+
8+
#mySQL Database Configurations
9+
#spring.datasource.url=jdbc:mysql://sql6.freesqldatabase.com:3306/sql6472211
10+
#spring.datasource.username=sql6472211
11+
#spring.datasource.password=BKZrwMePLL
912
#spring.datasource.driver-class-name=com.mysql.jdbc.Driver
10-
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
13+
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
1114
#spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
12-
spring.jpa.show-sql: true
1315

16+
# Connecting to Postgres Database
17+
#spring.datasource.url=jdbc:postgresql://host:port/database
18+
spring.datasource.url=jdbc:postgresql://free-tier12.aws-ap-south-1.cockroachlabs.cloud:26257/swarna-db-200.defaultdb
19+
spring.datasource.username=swarnadeep
20+
spring.datasource.password=uLYrds69nT_WNO5vEQn9rQ
21+
spring.datasource.driver-class-name=org.postgresql.Driver
22+
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
1423

1524
#Below 2 lines will be used by Actuator
1625
management.port=8080
Binary file not shown.
Binary file not shown.

target/classes/application.properties

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
server.port=8080
22

3-
#mySQL Database Configurations
3+
#JPA config
44
#update means directly change in db while I run application
55
spring.jpa.hibernate.ddl-auto:update
6-
spring.datasource.url=jdbc:mysql://sql6.freesqldatabase.com:3306/sql6472211
7-
spring.datasource.username=sql6472211
8-
spring.datasource.password=BKZrwMePLL
6+
spring.jpa.show-sql: true
7+
8+
#mySQL Database Configurations
9+
#spring.datasource.url=jdbc:mysql://sql6.freesqldatabase.com:3306/sql6472211
10+
#spring.datasource.username=sql6472211
11+
#spring.datasource.password=BKZrwMePLL
912
#spring.datasource.driver-class-name=com.mysql.jdbc.Driver
10-
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
13+
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
1114
#spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
12-
spring.jpa.show-sql: true
1315

16+
# Connecting to Postgres Database
17+
#spring.datasource.url=jdbc:postgresql://host:port/database
18+
spring.datasource.url=jdbc:postgresql://free-tier12.aws-ap-south-1.cockroachlabs.cloud:26257/swarna-db-200.defaultdb
19+
spring.datasource.username=swarnadeep
20+
spring.datasource.password=uLYrds69nT_WNO5vEQn9rQ
21+
spring.datasource.driver-class-name=org.postgresql.Driver
22+
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
1423

1524
#Below 2 lines will be used by Actuator
1625
management.port=8080

0 commit comments

Comments
 (0)