首页 > 其他分享 >Maven 创建SpringBoot

Maven 创建SpringBoot

时间:2022-09-25 16:58:15浏览次数:46  
标签:SpringBoot 创建 boot springframework Maven spring org import public

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo2</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo2</name>
    <description>demo2</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

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

</project>

package org.example;

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

/**
 * 主要
 *
 * @author liuzonglin
 * @date 2022/09/22
 * @SpringBootApplication 标记为 SpringBoot 启动类(入口)
 *		@Configuration spring.xml 也是配置类	
 *		@ComponentScan 扫描包 == <context:component-scan basePackages="org.springframework.boot"></context:component-scan>
 * Spring 底层在解析配置类时,会去解析 @ComponentScan,读取 basePackages,如果没有读取到,会将当前配置类所在的包当做扫描包
 */
@SpringBootApplication
public class Main {
    public static void main(String[] args) {
        SpringApplication.run(Main.class, args);
    }
}
package org.example.controller;

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

/**
 * 控制器
 *
 * @author liuzonglin
 * @date 2022/09/22
 * @RestController @Controller + @ResponseBody
 */
@RestController
public class Controller {


    /**
     * 你好
     *
     * @return {@link String}
     *<a href="http://127.0.0.1:8080/hello">...</a>
     */
    @RequestMapping("/hello")
    public String hello() {
        return "hello world";
    }
}

标签:SpringBoot,创建,boot,springframework,Maven,spring,org,import,public
From: https://www.cnblogs.com/liuzonglin/p/16728154.html

相关文章