I'm trying to do a http://spring.io/guides/gs/rest-service/ tutorial, and I did everything like it is in tutorial.
When I was trying to build with gradle with the gradle.build from the tutorial gradle build failed because of missing
springBoot {
mainClass = "main.java.hello.Application"
}
I did add it and now compilation start and finish correctly, but as soon as I'm trying to do
java -jar build/libs/gs-rest-service-0.1.0.jar
It throws an error
I have no idea what to do with it. Any help?
A Spring Boot application's main class is a class that contains a public static void main() method that starts up the Spring ApplicationContext. By default, if the main class isn't explicitly specified, Spring will search for one in the classpath at compile time and fail to start if none or multiple of them are found.
Method main is an entry point for standalone applications, so if you want to use spring boot standalone application, usually (if not always) packaged into a JAR - then yes, you should use main method. If you work with Web Applications, however, they don't have main method.
Spring Boot allows us to define the Main class in the configuration when we have multiple main classes declared in the application. As we are using a MAVEN build, we have to configure the POM.
It should be hello.Application
. main/java
is a part of package name / project dir structure.
When added the following piece of code to build.gradle:
springBoot {
mainClass = "hello.Application"
}
both ./gradlew clean bootRun
and ./gradlew clean build
with java -jar build/libs/gs-rest-service-0.1.0.jar
work well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With