File tree Expand file tree Collapse file tree 4 files changed +35
-8
lines changed
java/com/sopromadze/blogapi Expand file tree Collapse file tree 4 files changed +35
-8
lines changed Original file line number Diff line number Diff line change 3333 <artifactId >spring-boot-starter</artifactId >
3434 </dependency >
3535
36- <dependency >
37- <groupId >mysql</groupId >
38- <artifactId >mysql-connector-java</artifactId >
39- <scope >runtime</scope >
40- </dependency >
36+ <dependency >
37+ <groupId >com.mysql</groupId >
38+ <artifactId >mysql-connector-j</artifactId >
39+ <version >8.4.0</version >
40+ <scope >runtime</scope >
41+ </dependency >
4142
4243 <dependency >
4344 <groupId >org.projectlombok</groupId >
Original file line number Diff line number Diff line change 88
99public interface RoleRepository extends JpaRepository <Role , Long > {
1010 Optional <Role > findByName (RoleName name );
11+ boolean existsByName (RoleName name );
1112}
Original file line number Diff line number Diff line change 1+ package com .sopromadze .blogapi .utils ;
2+
3+ import com .sopromadze .blogapi .model .role .Role ;
4+ import com .sopromadze .blogapi .model .role .RoleName ;
5+ import com .sopromadze .blogapi .repository .RoleRepository ;
6+ import org .springframework .beans .factory .annotation .Autowired ;
7+ import org .springframework .boot .CommandLineRunner ;
8+ import org .springframework .stereotype .Component ;
9+
10+ @ Component
11+ public class RoleInitializer implements CommandLineRunner {
12+ @ Autowired
13+ private RoleRepository roleRepository ;
14+
15+ public void run (String ... args ){
16+ if (!roleRepository .existsByName (RoleName .ROLE_ADMIN )){
17+ roleRepository .save (new Role (RoleName .ROLE_ADMIN ));
18+ }
19+ if (!roleRepository .existsByName (RoleName .ROLE_USER )){
20+ roleRepository .save (new Role (RoleName .ROLE_USER ));
21+ }
22+
23+ System .out .println ("Role Initialized Successfully" );
24+ }
25+ }
Original file line number Diff line number Diff line change 11spring :
22 datasource :
3- url : jdbc:mysql://blogapi-db :3306/blogapi?useSSL=false&serverTimezone=UTC& allowPublicKeyRetrieval=true
3+ url : jdbc:mysql://localhost :3306/blogapi?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
44 username : root
5- password : root
5+ password : ??@@suhad@@??
66 jpa :
77 hibernate :
8- ddl-auto : none
8+ ddl-auto : update
99 show-sql : true
1010 properties :
1111 hibernate :
You can’t perform that action at this time.
0 commit comments