I am researching how to call a method from the terminal.
@Component
public class ApplicationAdapter implements CommandLineRunner {
@Autowired
private IApplicationPort iApplicationPort;
@Override
public void run(String... args) throws Exception {
iApplicationPort.getAll();
iApplicationPort.deleteStudentById((long) 1);
}
}
This is the main class
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
new ApplicationAdapter();
}
}
I wish to call the 2 methods: getAll();
and deleteStudentById((long) 1);
from the terminal. How can I do that?
First you don't need to instantiate the ApplicationAdapter. This will be done by Spring because of the @Component annotation:
Then you could use parameters that you pass when staring the application:
Then you can start your app like: