Class UserSeeder
java.lang.Object
com.needleandstitch.pavuk.data.UserSeeder
- All Implemented Interfaces:
org.springframework.boot.CommandLineRunner
@Component
@Order(2)
public class UserSeeder
extends Object
implements org.springframework.boot.CommandLineRunner
Seeder class for initializing default users in the database.
This class checks that certain users are present in the database and adds
them if they are missing.
The seeding process is triggered during application startup.
- Since:
- 15.12.2024
- Version:
- 1.0.0
- Author:
- Needle & Stitch
-
Constructor Summary
ConstructorsConstructorDescriptionUserSeeder
(UserRepository userRepository, RoleRepository roleRepository, org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder passwordEncoder) Constructs a new UserSeeder with the specified repository. -
Method Summary
-
Constructor Details
-
UserSeeder
public UserSeeder(UserRepository userRepository, RoleRepository roleRepository, org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder passwordEncoder) Constructs a new UserSeeder with the specified repository.- Parameters:
userRepository
- The repository used for interacting with the User entitiesroleRepository
- The repository used for interacting with the Role entitiespasswordEncoder
- The password encoder for hashing and verifying passwords
-
-
Method Details
-
run
Seeds the database with default users if they are not already present.- Specified by:
run
in interfaceorg.springframework.boot.CommandLineRunner
- Parameters:
args
- The command-line arguments passed to the application- Throws:
Exception
- if any error occurs during the seeding process
-