New springboot project
A simple hello project
pom dependency
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
application configuration file
# 应用服务 WEB 访问端口
server.port=9000
# thymeleaf配置
spring.thymeleaf.cache= false
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.servlet.content-type=text/html
index.html page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>hello</title>
</head>
<body>
<h1>hello 琛琛</h1>
</body>
</html>
Test page interface DemoController
package com.example.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @author lzh
* @version 1.0
* @description: TODO
* @date 2021/1/24 15:44
*/
@Controller
@RequestMapping("/lzh")
public class DemoController {
@GetMapping("/index")
public String index() {
return "index";
}
}
Package the springboot project
Upload to server
Put the jar package just packed in the corresponding directory
Alibaba Cloud open port 9000 (9000 I wrote above)
Jump to the directory where you just put the jar package, and enter the following commands in the command line
firewall-cmd --zone=public --add-port=9000/tcp --permanent # 开端口
systemctl restart firewalld.service # 重启服务器
firewall-cmd --list-ports # 查看该端口是否开放
nohup java -jar demo-0.0.1-SNAPSHOT.jar >/dev/null 2>&1 & # 发布项目(名字为刚刚jar包的名字)