How to start Spring Quick Boot Start Code
I'm new to Spring and Spring Boot and I've tried this. I am having a problem running the code from https://projects.spring.io/spring-boot/ .
package hello;
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;
@Controller
@EnableAutoConfiguration
public class SampleController {
@RequestMapping("/")
@ResponseBody
String home() {
return "Hello World!";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleController.class, args);
}
}
I have released mvn install
and everything seems fine. But then I java -cp target/myArtifId-1.0-SNAPSHOT.jar hello.SampleController
threw a ClassNotFoundException too.
How do I run this sample code?
source to share
According to spring boot documentation , you can start your application with this command:
java -jar target/myArtifId-1.0-SNAPSHOT.jar
spring Boot creates executable jar, no need to specify java class with method main
. This is also the reason why you might not want to include another class with a method main
.
source to share