从零开始部署springboot到服务器上
创建springboot项目
接下来就是的等待安装依赖,安装完之后进行下一步
写下“hello world”
在app.java
里面
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@SpringBootApplication
public class DemoApplication {
@RequestMapping("/")
public String home() {
return "Hello World!";
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
部署到服务器中
利用IDEA
里面的工具打包
在项目工程的target
目录下形成一个jar包
利用远程连接工具传输到服务器上
执行jar文件
java -jar demo-0.0.1-SNAPSHOT.jar
ok,这时候打开浏览器输入服务器ip:8080
即可看到hello world!
为了避免关闭终端结束java进程我们可以进行后台启动
nohup java -jar demo-0.0.1-SNAPSHOT.jar > demo.log &