Search in sources :

Example 1 with AccountService

use of com.apistudy.restapi.accounts.AccountService in project spring-study by backtony.

the class AppConfig method applicationRunner.

// 그냥 스프링 뜰때 유저 하나 넣어준 거임
@Bean
public ApplicationRunner applicationRunner() {
    return new ApplicationRunner() {

        @Autowired
        AccountService accountService;

        @Autowired
        AppProperties appProperties;

        @Override
        public void run(ApplicationArguments args) throws Exception {
            Account admin = Account.builder().email(appProperties.getAdminUsername()).password(appProperties.getAdminPassword()).roles(Set.of(AccountRole.ADMIN, AccountRole.USER)).build();
            accountService.saveAccount(admin);
            Account user = Account.builder().email(appProperties.getUserUsername()).password(appProperties.getUserPassword()).roles(Set.of(AccountRole.USER)).build();
            accountService.saveAccount(user);
        }
    };
}
Also used : Account(com.apistudy.restapi.accounts.Account) ApplicationRunner(org.springframework.boot.ApplicationRunner) AccountService(com.apistudy.restapi.accounts.AccountService) AppProperties(com.apistudy.restapi.common.AppProperties) ApplicationArguments(org.springframework.boot.ApplicationArguments) Bean(org.springframework.context.annotation.Bean)

Aggregations

Account (com.apistudy.restapi.accounts.Account)1 AccountService (com.apistudy.restapi.accounts.AccountService)1 AppProperties (com.apistudy.restapi.common.AppProperties)1 ApplicationArguments (org.springframework.boot.ApplicationArguments)1 ApplicationRunner (org.springframework.boot.ApplicationRunner)1 Bean (org.springframework.context.annotation.Bean)1