Package com.sivalabs.springmvc.config

Source Code of com.sivalabs.springmvc.config.DBInitializer

/**
*
*/
package com.sivalabs.springmvc.config;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.sivalabs.springmvc.entities.User;
import com.sivalabs.springmvc.services.UserService;

/**
* @author Siva
*
*/
@Component
public class DBInitializer
{
  private static Logger logger = LoggerFactory.getLogger(DBInitializer.class);

  @Autowired
  private UserService userService;

  @Value("${init-db:false}")
  private String initDatabase;

  @PostConstruct
  public void init()
  {
    try {
      logger.info("############## InitDatabase :" + initDatabase + " ########################");
      if (Boolean.parseBoolean(initDatabase)) {
        initDatabase();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  void initDatabase()
  {

    logger.info("Initializing Database with sample data");
   
   
    User user1 = new User(1, "admin@gmail.com", "admin", "Administrator");
    User user2 = new User(2, "siva@gmail.com", "siva""Siva");
   
   
    userService.createUser(user1);
    userService.createUser(user2);
   
  }
}
TOP

Related Classes of com.sivalabs.springmvc.config.DBInitializer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.