Class DataInitializer

java.lang.Object
com.deusto.coffeestack.config.DataInitializer
All Implemented Interfaces:
org.springframework.boot.ApplicationRunner

@Component public class DataInitializer extends Object implements org.springframework.boot.ApplicationRunner
Creates the default ROOT admin user on startup if it doesn't already exist.

This solves the chicken-and-egg problem: the first time the app starts there are no users, so nobody can create users. This initializer inserts the seed user admin / admin123 using the application's own PasswordEncoder, so the hash is always correct regardless of the BCrypt rounds configured.

The SQL migration V3 no longer needs the INSERT — this handles it.

  • Constructor Details

    • DataInitializer

      public DataInitializer(UsuarioRepository usuarioRepository, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder)
  • Method Details

    • run

      public void run(org.springframework.boot.ApplicationArguments args)
      Specified by:
      run in interface org.springframework.boot.ApplicationRunner