добавил создание пользователя по умолчанию при первом старте

This commit is contained in:
Anton Romanov 2023-12-05 16:18:29 +04:00
parent 5621b809f7
commit 7c47c79823

View File

@ -1,13 +1,30 @@
package com.gipro.giprolab; package com.gipro.giprolab;
import com.gipro.giprolab.models.UserDto;
import com.gipro.giprolab.services.UserService;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
@SpringBootApplication @SpringBootApplication
public class GiprolabApplication { public class GiprolabApplication {
private final UserService userService;
public GiprolabApplication(UserService userService) {
this.userService = userService;
}
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(GiprolabApplication.class, args); SpringApplication.run(GiprolabApplication.class, args);
} }
@EventListener(ApplicationReadyEvent.class)
public void doSomethingAfterStartup() {
if (userService.getUserByLogin("user@user.ru") == null) {
userService.createDefaultRoles();
userService.createUser(new UserDto("user@user.ru", "user"));
}
}
} }