Removed 2 classes for main and other for Runner. Replaced them with a single class serving both the purposes

This commit is contained in:
hemant 2018-06-16 01:01:14 +05:30
parent 98d37d0f8c
commit 400f86a657
3 changed files with 37 additions and 44 deletions

View File

@ -1,23 +0,0 @@
package com.baeldung.springbootnonwebapp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
@Component
public class Runner implements CommandLineRunner {
private static final Logger LOG = LoggerFactory.getLogger(Runner.class);
/**
* This method will be executed after the application context is loaded and
* right before the Spring Application main method is completed.
*/
@Override
public void run(String... args) throws Exception {
LOG.info("START : command line runner");
LOG.info("EXECUTING : command line runner");
LOG.info("END : command line runner");
}
}

View File

@ -0,0 +1,37 @@
package com.baeldung.springbootnonwebapp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* 1. Act as main class for spring boot application
* 2. Also implements CommandLineRunner, so that code within run method
* is executed before application startup but after all beans are effectively created
* @author hemant
*
*/
@SpringBootApplication
public class SpringBootConsoleApplication implements CommandLineRunner {
private static final Logger LOG = LoggerFactory.getLogger(SpringBootConsoleApplication.class);
public static void main(String[] args) {
LOG.info("STARTING THE APPLICATION");
SpringApplication.run(SpringBootConsoleApplication.class, args);
LOG.info("APPLICATION STARTED");
}
/**
* This method will be executed after the application context is loaded and
* right before the Spring Application main method is completed.
*/
@Override
public void run(String... args) throws Exception {
LOG.info("START : command line runner");
LOG.info("EXECUTING : command line runner");
LOG.info("END : command line runner");
}
}

View File

@ -1,21 +0,0 @@
package com.baeldung.springbootnonwebapp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringBootNonWebappApplication {
private static final Logger LOG = LoggerFactory.getLogger(SpringBootNonWebappApplication.class);
public static void main(String[] args) {
LOG.info("STARTING THE APPLICATION");
SpringApplication app = new SpringApplication(SpringBootNonWebappApplication.class);
// This line of code, disables the web app setting
app.setWebEnvironment(false);
app.run(args);
LOG.info("APPLICATION STARTED");
}
}