Professional Documents
Culture Documents
SpringBoot6PM 30042020
SpringBoot6PM 30042020
javabyraghu@gmail.com
https://www.facebook.com/groups/thejavatemple/
============================================================================
Q) How many runners can we define in one Spring Boot Project?
A) Multiple Runners.
For Example: JdbcRunner, BatchExRunner, MongoDbSetupRunner,..etc
=>Execution order is R#4 -> R#2 -> R#3 -> R#1 -> R#5
@Override
public void run(String... args) throws Exception {
System.out.println("from Email Test Runner-8");
}
}
---------------
package in.nit.runner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@Component
@Order(6)
public class DevAppTestRunner implements CommandLineRunner{
@Override
public void run(String... args) throws Exception {
System.out.println("from DevAppTest Runner-6");
}
}
------------------
package in.nit.runner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@Component
@Order(6)
public class BatchExRunner implements CommandLineRunner{
@Override
public void run(String... args) throws Exception {
System.out.println("from Batch Runner-6");
}
}
****************************************************************************
----------------------- Order in Legacy Style ----------------------------
****************************************************************************
We can also use one interface : Ordered
It is having one abstract method : getOrder():int
We can implement our runner using this interface and override this
method and provide one int value.
-----------Example code--------------------
package in.nit.runner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
//ctrl+shift+O (imports)
@Component
//@Order(10)
public class JdbcTestRunner implements CommandLineRunner,Ordered{
@Override
public void run(String... args) throws Exception {
System.out.println("from JDBC Test Runner-5");
}
@Override
public int getOrder() {
return 4;
}
Number Systems:
.... -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 ...