If Spring boot application has multiple classes which have (for any reason) –
- @SpringBootApplication annotation
then while running the application as
jar, you can face this error.
>> mvn spring-boot:run ... ... [ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.1.RELEASE:run (default-cli) on project main-class: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.0.1.RELEASE:run failed: Unable to find a single main class from the following candidates [com.springexamples.demo.MainClassTwo, com.springexamples.demo.MainClassOne] -> [Help 1]
To solve this problem, configure the
start-class property in
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <!-- The main class to start --> <start-class>com.springexamples.demo.MainClassOne</start-class> </properties>
Now when you run the application again, you will not get this error and application will be started with
MainClassOne as spring boot application starter class.