Spring Boot 的第一个程序
这是我写过时间最长的hello world 程序。
找不到符号 ‘SpringApplication’ 问题
这是我见过最奇葩的问题了,不知道为什么,上网搜了无数遍都没有人遇到,对照官网文档看了好多遍也没有问题,简直有病。
最后我重新设置了maven就好了,神奇。
抛出了奇怪异常
经由我大胆猜测,是8080端口被占用。
改成这个例子:
package cn.czwfun;
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;
@RestController
@SpringBootApplication
public class DemoApplication implements EmbeddedServletContainerCustomizer {
@RequestMapping("/")
String home() {
return "Hello World!";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(DemoApplication.class, args);
}
@Override
public void customize(ConfigurableEmbeddedServletContainer configurableEmbeddedServletContainer) {
configurableEmbeddedServletContainer.setPort(32768);
}
}