Why is the SpringApplication.run() inside the class that it runs?

Viewed 52

I'm new to SpringBoot and I've been a long time without coding with Java. In my mind this doesn't make sense. Why is the SpringApplication.run() inside the class that it runs ?

Like so:

@SpringBootApplication
public class ConsumingRestApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConsumingRestApplication.class, args);
    }
}
1 Answers

Because there is no practical need.

Technically you could do something like that:

@SpringBootApplication
public class ConsumingRestApplicationĀ {}

public class Init {
    public static void main(String[] args) {
        SpringApplication.run(ConsumingRestApplication.class, args);
    }
}

But you wouldn't gain anything from it, that's why it's just simplified into one class with the annotation and the main method.

Related