summaryrefslogtreecommitdiff
path: root/src/main/java/com/mavlushechka/studentdatabase/Application.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/mavlushechka/studentdatabase/Application.java')
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/Application.java33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/main/java/com/mavlushechka/studentdatabase/Application.java b/src/main/java/com/mavlushechka/studentdatabase/Application.java
new file mode 100755
index 0000000..275d756
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/Application.java
@@ -0,0 +1,33 @@
+package com.mavlushechka.studentdatabase;
+
+import com.mavlushechka.studentdatabase.domain.Role;
+import com.mavlushechka.studentdatabase.repository.RoleRepository;
+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;
+
+@SpringBootApplication
+public class Application {
+ @Autowired
+ private RoleRepository roleRepository;
+
+ public static void main(String[] args) {
+ SpringApplication.run(Application.class, args);
+ }
+
+ private void saveRole(String role) {
+ if (roleRepository.findByRole(role) == null) {
+ roleRepository.save(new Role(role));
+ }
+ }
+
+ @Bean
+ CommandLineRunner init() {
+ return args -> {
+ saveRole("ADMIN");
+ saveRole("USER");
+ };
+ }
+} \ No newline at end of file