SpringBoot3基础:最简项目示例

说明

本文建立一个最基本的SpringBoot3项目,依赖项仅包含 spring-web(SpringMVC)

备注:SpringBoot3需要JDK17支持,配置方法参考:
SpringBoot3项目中配置JDK17

项目结构图示

SpringBoot3基础:最简项目示例_第1张图片

POM


<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>
    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>3.1.3version>
        <relativePath/> 
    parent>
    <groupId>com.examplegroupId>
    <artifactId>hello-spring-boot3artifactId>
    <version>1.0version>
    <name>HelloSpringBoot3name>
    <description>Demo project for Spring Boot3description>
    <properties>
        <java.version>17java.version>
    properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
            <scope>testscope>
        dependency>
    dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.yamlgroupId>
                <artifactId>snakeyamlartifactId>
                <version>2.0version>
            dependency>
        dependencies>
    dependencyManagement>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
            plugin>
        plugins>
    build>

project>

启动器:Application

package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class HelloSpringBoot3Application {

    public static void main(String[] args) {
        SpringApplication.run(HelloSpringBoot3Application.class, args);
    }

}

配置文件:yml

使用的默认配置,未添加任何内容。

控制器:Controller

package com.example.web.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("test")
public class TestController {

    @GetMapping("hello")
    public String hello() {
        return "Hello SpringBoot3";
    }

}

接口调用示例

SpringBoot3基础:最简项目示例_第2张图片

你可能感兴趣的:(Spring,Boot,3,java,spring,boot)