blob: 997128e3801b2b521a3aba63eebb2566eb8774c0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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);
}
@Bean
CommandLineRunner init() {
return args -> {
saveRole("ADMIN");
saveRole("USER");
};
}
private void saveRole(String role) {
if (roleRepository.findByRole(role) == null) {
roleRepository.save(new Role(role));
}
}
}
|