Reputation: 561
I want to use spring-data & IOC container for some test app.
And the problem is: how to bootstrap the app? In case of spring-mvc we move from controllers, but how to do this without mvc?
I need some main-like method for my code, but the application public static void main
is already used for spring initialization:
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
So, where should I place my code?
Upvotes: 1
Views: 491
Reputation: 33091
There is a CommandLineRunner
interface that just means to do that.
@Service
class FooBar implements CommandLineRunner {
// Inject whatever collaborator you need
@Override
void run(String... args) throws Exception {
// Execute whatever you need.
// command-line arguments are available if you need them
}
}
Upvotes: 3