すぐにプロジェクトをビルドspringboot

1.問題の説明

ただ、既存のMaven GAVにspringbootの達人に基づいて、実際には、開発の効率を向上させる大幅に、Java開発者のための偉大な恩恵であることを、立ち上げをspringboot最も簡単なコードクイックスタートspringbootで、今日それをカプセル化されています。

2.ソリューション

アイデアは、あなたが有料版(LANゆうを取り締まるためのおかげで)、達人のアイデア、gitの、その他のプラグインより良いのサポートを使用することを強くお勧めします。

使用アイデア春Initializr(実際の呼び出しはinitializrのspringbootの公式ウェブサイトです)、新しい高速springbootプロジェクトが付属しています。

2.1新しいSpringbootプロジェクト

(1)[ファイル] - > [新規作成]> [プロジェクト

(2)次をクリックします(最初の)

springbootプロジェクトの作成(次時には数秒の遅れ、海外のサイトが接続されているので)、独自の構成、グループへの二つの値:com.laowang、アーティファクト:sptestの、他には[OK]をクリックし、移動することはできません

(3)次をクリックします(秒)

WEB-「春のWebスターターを選択

(4)次の(第3)をクリック

完了するために直接変更を加えないでください。

新springbootプロジェクトが完了しています。

2.2 springboot 3つのファイルがデフォルトで生成します

3を生成し、デフォルトのファイル

2.2.1。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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.laowang</groupId>
    <artifactId>sptest</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>sptest</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

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

</project>

GAVに焦点を当てる:春・ブート・スターター・ウェブ、他は削除することができます。

2.2.2 application.properties

8080、ファイルを変更するように変更することができます。ファイルは、デフォルトでは、springbootのデフォルトの起動ポート番号が空です。

2.2.3スタートクラスファイル(SptestApplication.java)
package com.laowang.sptest;

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

@SpringBootApplication
public class SptestApplication {

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

}

フォーカスは、ラベルに記載されて:@SpringBootApplication

2.3 springbootを確認

com.laowang.sptestでCtroller新しいパケットが報告され、新しいカテゴリ:HelloController

package com.laowang.sptest.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

@Controller
public class HelloController {

    @RequestMapping("/")
    @ResponseBody
    public String getHello() {
        return "hello";
    }
}

結果の実装:

サービスが正常に起動します。

2.4のハイライト

二つのことに注意してください。

(1)类文件要放在跟启动类同级或者下一目录下,本项目为:com.laowang.sptest包下面。因为springboot默认扫描加载启动类同级或者下级目录的标签类(@RestController,@Service ,@Configuraion,@Component等),假如真需要加载其他目录的标签类,可以通过在启动上配置标签@ComponentScan(具体包)来进行扫描加载。

(2)资源文件默认放到resources下面,templates默认放的是动态文件,比如:html文件,不过要搭配thymeleaf 使用(pom文件中需新加gav)。

其他也没什么了,springboot主要是通过spring提供的多个starter和一些默认约定,实现项目的快速搭建。


I’m 「软件老王」,如果觉得还可以的话,关注下呗,后续更新秒知!欢迎讨论区、同名公众号留言交流!

おすすめ

転載: www.cnblogs.com/ruanjianlaowang/p/11222395.html