Does an abstract Spring Boot app work?

Last Update: 28.09.2018. By Jens in Newsletter

Sometimes students do things I never thought about doing at all before. It astonishes me but it will also always teach me something. Like in a recent training, where one student made the Spring Boot application class abstract like:

@SpringBootApplication public abstract class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } } It works.

The main method is static so Java can even call it on an abstract class, which surprised me at first. But when you think about it, it fits the concept. However, it never came to my mind to do that.

Spring Boot is still able to use it as the Configuration* class and the application started fine.

The drawback came in the tests, where Spring Boot Test was not able to find the main configuration class anymore. The exception was:

java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=…) with your test Interesting. Anyways, I haven’t looked up why.