• 创建SpringBoot项目的两种方式


    一、线上初始化:https://start.spring.io/

    File -> New -> Project...

     

    二、创建Maven项目

     创建完成后修改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>
        <!--Spring Boot的父依赖-->
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.2.4.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
    
        <groupId>com.linhw</groupId>
        <artifactId>helloworld</artifactId>
        <version>1.0-SNAPSHOT</version>
        <!-- SpringBoot的打包方式:pom/jar/war-->
        <packaging>jar</packaging>
    
        <properties>
            <!-- JDK 1.8 -->
            <java.version>1.8</java.version>
        </properties>
        <dependencies>
            <!-- 核心启动器, 包括auto-configuration、logging and YAML -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>
            <!-- testing Spring Boot applications with libraries including JUnit, Hamcrest and Mockito -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    </project>

    常见SpringBoot的启动类:

    package com.linhw.demo;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    public class HelloworldApp {
        public static void main(String[] args) {
            SpringApplication.run(HelloworldApp.class, args);
        }
    }

    在src/main/resources下创建application.properties或application.yml

    注:因为不是web项目,所以启动后就会马上停止。

  • 相关阅读:
    A. Difference Row
    B. Fixed Points
    命运
    Climbing Worm
    大学感想
    Constructing Roads
    lintcode605- Sequence Reconstruction- medium- airbnb google
    lintcode616- Course Schedule II- medium
    lintcode615- Course Schedule- medium
    lintcode127- Topological Sorting- medium
  • 原文地址:https://www.cnblogs.com/myitnews/p/11516347.html
Copyright © 2020-2023  润新知