Skip to content

Instantly share code, notes, and snippets.

@jdmr
Created November 9, 2012 17:07
Show Gist options
  • Select an option

  • Save jdmr/4046886 to your computer and use it in GitHub Desktop.

Select an option

Save jdmr/4046886 to your computer and use it in GitHub Desktop.
Spring Bootstrap Configuration
package edu.swau.forms.utils;
import edu.swau.forms.dao.RoleDao;
import edu.swau.forms.dao.UserDao;
import edu.swau.forms.model.Role;
import edu.swau.forms.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.transaction.annotation.Transactional;
/**
*
*/
public class Bootstrap implements ApplicationListener<ContextRefreshedEvent> {
private static final Logger log = LoggerFactory.getLogger(Bootstrap.class);
@Autowired
private RoleDao roleDao;
@Autowired
private UserDao userDao;
@Override
@Transactional
public void onApplicationEvent(ContextRefreshedEvent e) {
log.info("Validating roles");
log.debug("Looking for {}", Constants.ROLE_ADMIN);
Role adminRole = roleDao.get(Constants.ROLE_ADMIN);
if (adminRole == null) {
adminRole = new Role(Constants.ROLE_ADMIN, 1);
roleDao.create(adminRole);
}
log.debug("Looking for {}", Constants.ROLE_USER);
Role userRole = roleDao.get(Constants.ROLE_USER);
if (userRole == null) {
userRole = new Role(Constants.ROLE_USER, 10);
roleDao.create(userRole);
}
log.info("Validating users");
// TODO: Well, you get the idea... right?
log.info("Forms Application is up");
}
}
<bean id="bootstrap" class="edu.swau.forms.utils.Bootstrap" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment