From 6ec4e8ccf378466c6a2bf705554f3619a1c57a1a Mon Sep 17 00:00:00 2001 From: Adilet K Date: Thu, 15 Jun 2023 21:25:49 +0600 Subject: [PATCH 1/3] add: Using Profiles in Spring Boot Blog App --- src/main/resources/application-dev.properties | 9 +++++++ .../resources/application-prod.properties | 9 +++++++ src/main/resources/application-qa.properties | 9 +++++++ src/main/resources/application.properties | 24 ++++++++++--------- 4 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 src/main/resources/application-dev.properties create mode 100644 src/main/resources/application-prod.properties create mode 100644 src/main/resources/application-qa.properties diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties new file mode 100644 index 0000000..575856e --- /dev/null +++ b/src/main/resources/application-dev.properties @@ -0,0 +1,9 @@ +spring.datasource.url=jdbc:mysql://localhost:3306/myblog +spring.datasource.username=bestuser +spring.datasource.password=bestuser + +# hibernate properties +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect + +# hibernate ddl auto (create, create-drop, validate, update) +spring.jpa.hibernate.ddl-auto=update \ No newline at end of file diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties new file mode 100644 index 0000000..575856e --- /dev/null +++ b/src/main/resources/application-prod.properties @@ -0,0 +1,9 @@ +spring.datasource.url=jdbc:mysql://localhost:3306/myblog +spring.datasource.username=bestuser +spring.datasource.password=bestuser + +# hibernate properties +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect + +# hibernate ddl auto (create, create-drop, validate, update) +spring.jpa.hibernate.ddl-auto=update \ No newline at end of file diff --git a/src/main/resources/application-qa.properties b/src/main/resources/application-qa.properties new file mode 100644 index 0000000..575856e --- /dev/null +++ b/src/main/resources/application-qa.properties @@ -0,0 +1,9 @@ +spring.datasource.url=jdbc:mysql://localhost:3306/myblog +spring.datasource.username=bestuser +spring.datasource.password=bestuser + +# hibernate properties +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect + +# hibernate ddl auto (create, create-drop, validate, update) +spring.jpa.hibernate.ddl-auto=update \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b668349..44c0931 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,14 +1,16 @@ -spring.datasource.url=jdbc:mysql://localhost:3306/myblog -spring.datasource.username=bestuser -spring.datasource.password=bestuser -# hibernate properties -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect -# hibernate ddl auto (create, create-drop, validate, update) -spring.jpa.hibernate.ddl-auto=update -#spring.security.user.name=user -#spring.security.user.password=user -#spring.security.user.roles=ADMIN +#spring.datasource.url=jdbc:mysql://localhost:3306/myblog +#spring.datasource.username=bestuser +#spring.datasource.password=bestuser +## hibernate properties +#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect +## hibernate ddl auto (create, create-drop, validate, update) +#spring.jpa.hibernate.ddl-auto=update +##spring.security.user.name=user +##spring.security.user.password=user +##spring.security.user.roles=ADMIN #secret javaproject app.jwt-secret=ce02356f9917223373f26bb97ef5c3e4fafef9cde898bf9cf960e7d08e74ffef -app-jwt-expiration-milliseconds=604800000 \ No newline at end of file +app-jwt-expiration-milliseconds=604800000 + +spring.profiles.active=dev \ No newline at end of file From acb7075f5c6acd9999874f86662cb034d9844d5c Mon Sep 17 00:00:00 2001 From: Adilet K Date: Thu, 15 Jun 2023 21:37:46 +0600 Subject: [PATCH 2/3] add: Write a Code to Insert Metadata in Tables --- .../SpringbootBlogRestApiApplication.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/springboot/blog/SpringbootBlogRestApiApplication.java b/src/main/java/com/springboot/blog/SpringbootBlogRestApiApplication.java index 249a598..349a0e5 100644 --- a/src/main/java/com/springboot/blog/SpringbootBlogRestApiApplication.java +++ b/src/main/java/com/springboot/blog/SpringbootBlogRestApiApplication.java @@ -1,11 +1,15 @@ package com.springboot.blog; +import com.springboot.blog.entity.Role; +import com.springboot.blog.repository.RoleRepository; import io.swagger.v3.oas.annotations.ExternalDocumentation; import io.swagger.v3.oas.annotations.OpenAPIDefinition; import io.swagger.v3.oas.annotations.info.Contact; import io.swagger.v3.oas.annotations.info.Info; import io.swagger.v3.oas.annotations.info.License; import org.modelmapper.ModelMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; @@ -31,7 +35,7 @@ url = "https://github.com/adiletkdev/springboot-blog-rest-api" ) ) -public class SpringbootBlogRestApiApplication { +public class SpringbootBlogRestApiApplication implements CommandLineRunner { @Bean public ModelMapper modelMapper() { @@ -42,4 +46,17 @@ public static void main(String[] args) { SpringApplication.run(SpringbootBlogRestApiApplication.class, args); } + @Autowired + private RoleRepository roleRepository; + + @Override + public void run(String... args) throws Exception { + Role adminRole = new Role(); + adminRole.setName("ROLE_ADMIN"); + roleRepository.save(adminRole); + + Role userRole = new Role(); + userRole.setName("ROLE_USER"); + roleRepository.save(userRole); + } } From 54667c263052162af796e60c1c0afdad83fbae3c Mon Sep 17 00:00:00 2001 From: Adilet K Date: Thu, 29 Jun 2023 16:54:44 +0600 Subject: [PATCH 3/3] add: Another app properties --- src/main/resources/application-prod.properties | 12 +++++++----- src/main/resources/application.properties | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 575856e..43231e6 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -1,9 +1,11 @@ -spring.datasource.url=jdbc:mysql://localhost:3306/myblog -spring.datasource.username=bestuser -spring.datasource.password=bestuser +spring.datasource.url=jdbc:mysql://javajdk.cwhtfxb3sdkv.eu-north-1.rds.amazonaws.com:3306/myblog +spring.datasource.username=root +spring.datasource.password=javajdk123 # hibernate properties -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect # hibernate ddl auto (create, create-drop, validate, update) -spring.jpa.hibernate.ddl-auto=update \ No newline at end of file +spring.jpa.hibernate.ddl-auto=update + +server.port=5000 \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 44c0931..362accb 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -13,4 +13,4 @@ app.jwt-secret=ce02356f9917223373f26bb97ef5c3e4fafef9cde898bf9cf960e7d08e74ffef app-jwt-expiration-milliseconds=604800000 -spring.profiles.active=dev \ No newline at end of file +spring.profiles.active=prod \ No newline at end of file