【发布时间】:2017-09-28 18:05:14
【问题描述】:
我是 Spring 和 Spring Boot 的新手,我正在尝试。我在运行来自 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);
}
}
我发出了mvn install,一切似乎都很好。但后来我发出了java -cp target/myArtifId-1.0-SNAPSHOT.jar hello.SampleController 并抛出了 ClassNotFoundException。
如何运行此代码示例?
【问题讨论】:
-
如果你是 spring-boot 的新手,请参考这个方法来启动。 stackoverflow.com/questions/39245732/…
-
您缺少@SpringBootApplication 注释
标签: spring spring-boot