SpringBoot-1、 vscode创建springboot项目

1、安装Extension Pack for java

image
另外安装Spring Boot Extension Pack

2、安装jdk11环境

sudo apt install openjdk-11-jdk-headless

3、在项目目录下创建src/main/java/com/example/app.java

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class app {
    public static void main(String[] args) {
	System.out.println("test\n");
    }
}

4、创建pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>spring-boot-demo</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>

    <name>Spring Boot Demo</name>
    <description>Spring Boot 2.5.x Demo Project</description>

    <properties>
        <java.version>11</java.version>
        <spring-boot.version>2.5.5</spring-boot.version>
        <mainClass>com.example.app</mainClass>
    </properties>

    <dependencies>
   
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>2.5.5</version>
        </dependency>
        <!-- Spring Boot Starter Web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>${spring-boot.version}</version>
        </dependency>

        <!-- Spring Boot Starter Test (Optional) -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>${spring-boot.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- Maven Compiler Plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>

            <!-- Spring Boot Maven Plugin -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring-boot.version}</version>
            </plugin>
        </plugins>
    </build>
</project>

4、运行

mvn clean compile && mvn spring-boot:run

image

5、另外一种比较简单方式

https://start.spring.io/
直接创建一个项目,下载打开,运行即可(首次比较慢)。

posted @ 2023-07-31 15:39  zhaogaojian  阅读(126)  评论(0编辑  收藏  举报