package com.northglass.applicationListener; import java.sql.SQLException; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.stereotype.Service; import com.northglass.log.GLoggerFactory; import com.northglass.service.device.DeviceService; import com.northglass.util.SetupUtil; @Service public class InitializeSystemApplicationListener implements ApplicationListener { private static final Logger LOGGER = GLoggerFactory.getLogger(InitializeSystemApplicationListener.class); @Autowired private DeviceService deviceService; @Override public void onApplicationEvent(ContextRefreshedEvent event) { LOGGER.debug("> Start onApplicationEvent"); try { if (SetupUtil.databaseExists()) { LOGGER.trace("event.getApplicationContext().getParent()"+event.getApplicationContext().getParent()); if (event.getApplicationContext().getParent() == null) { // systemService.resetState(); deviceService.resetState(); } else { // systemService.connect(); deviceService.connect(); } } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } LOGGER.debug("> End onApplicationEvent"); } }