Thanks I was also looking for the answer of this question.
Just to add - CommandLineRunner is an Interface, more precisely to say "functional interface", if I understand it correctly, in springboot that has only one method run(). Actually all the functional interface has only one abstract method, there could be default implementation or static method as well though.
So the point is - when we are returning a lambda in this context, basically we are returning an implementation of that run method of the functional interface commandlinerunner.
Thats how I understood. Some other useful information with example can be found here:
https://www.baeldung.com/spring-boot-console-app
We could also write the same thing as per the below example:
public class SpringBootConsoleApplication
implements CommandLineRunner {
private static 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 FINISHED");
}
@Override
public void run(String... args) {
LOG.info("EXECUTING : command line runner");
for (int i = 0; i < args.length; ++i) {
LOG.info("args[{}]: {}", i, args[i]);
}
}
}