8080端口被使用的比较多,Apache2和tomcat这些都默认使用的8080端口,在使用springboot时,默认也是8080端口,如果被占用的话可以通过下面方式来修改。
在src/resource/application.properties
加入server.port=8081
现在通过 http://localhost:8081即可访问。
创建的一个DemoController类代码如下:
package controller;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@EnableAutoConfiguration
public class DemoController {
@RequestMapping("/hello")
@ResponseBody
String home(){
return "Hello World!";
}
public static void main(String[] args) {
SpringApplication.run(DemoController.class,args);
}
}
本文介绍了如何在SpringBoot项目中更改默认的8080端口,通过修改application.properties文件中的server.port属性来实现,并提供了一个简单的DemoController类作为示例。
2152

被折叠的 条评论
为什么被折叠?



