Created
February 28, 2017 15:35
-
-
Save kappaj2/2aa0145200cc40ba5ec8bd2b74aece7e to your computer and use it in GitHub Desktop.
Creating a bean that will be executed when SpringBoot starts the main method.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.context.ConfigurableApplicationContext; | |
@SpringBootApplication | |
public class DriveScannerApplication { | |
private static Logger logger = LoggerFactory.getLogger(DriveScannerApplication.class); | |
/** | |
* Create a main method to execute when the Springboot application starts. | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
if (logger.isInfoEnabled()) { | |
logger.info("Starting application"); | |
} | |
final ConfigurableApplicationContext context = SpringApplication.run(DriveScannerApplication.class, args); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.boot.CommandLineRunner; | |
import org.springframework.stereotype.Component; | |
@Component | |
public class Test1 implements CommandLineRunner { | |
private Logger logger = LoggerFactory.getLogger(Test1.class); | |
/** | |
* This method overrides the run method as per interface specification. | |
* No need to call anything as Spring will search for beans implementing this interface and automatically execute the run method. | |
* | |
* @param strings | |
* @throws Exception | |
*/ | |
@Override | |
public void run(String... strings) throws Exception { | |
logger.info("LOGGER -> Inside test1 ..!!!!!!!!!!!!!!!!"); | |
try { | |
Thread.sleep(15000); | |
} catch (Exception ex) { | |
// Testing only so safe to swallow! | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment