Linux server releases springboot project (no domain name, only server deployment)

New springboot project

A simple hello project
Insert picture description here

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

Insert picture description here

Upload to server

Put the jar package just packed in the corresponding directory

Insert picture description here

Alibaba Cloud open port 9000 (9000 I wrote above)

Insert picture description here

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包的名字)

Enter [ip address+port number+interface] in the address bar to view

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44635198/article/details/113127947