欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

通過idea創(chuàng)建Spring Boot項(xiàng)目并配置啟動過程圖解

 更新時間:2019年11月12日 08:33:23   作者:King-D  
這篇文章主要介紹了通過idea創(chuàng)建Spring Boot項(xiàng)目并配置啟動過程圖解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下

 一、操作步驟

①使用idea新建一個Spring Boot項(xiàng)目

②修改pom.xml

③修改application.properties

④修改編寫一個Hello Spring Boot的Controller

⑤啟動項(xiàng)目訪問

二、詳細(xì)步驟

1、File-->New-->Project

2、選擇Spring Initializr 然后Next

3、輸入Artiface 然后Next

4、勾選Web 、模版我們選擇官方推薦的Thymeleaf模版引擎,其他框架、中間件、數(shù)據(jù)庫根據(jù)需要選擇即可,而且無需我們手動去添加配置文件等,選擇完成后Next

選擇模版引擎

5、Finish即可

6、查看Spring Boot項(xiàng)目結(jié)構(gòu)目錄

7、在pom.xml添加如下內(nèi)容

注意:如果新建項(xiàng)目時選擇了依賴的mybatis、mongodb之類的啟動時候會報錯,由于沒配置數(shù)據(jù)源及mongodb的連接信息,此時如果只是想測試項(xiàng)目是否搭建成功先注釋即可

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.1.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>
 
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
  </properties>
 
  <dependencies>
    <!--<dependency>-->
      <!--<groupId>org.springframework.boot</groupId>-->
      <!--<artifactId>spring-boot-starter-data-mongodb</artifactId>-->
    <!--</dependency>-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <!--<dependency>-->
      <!--<groupId>org.mybatis.spring.boot</groupId>-->
      <!--<artifactId>mybatis-spring-boot-starter</artifactId>-->
      <!--<version>1.3.2</version>-->
    <!--</dependency>-->
 
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

8、編寫Hello Spring Boot的Controller

package com.example.bootopen.com;
 
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
@RestController
public class HelloSpringBootController {
 
  @RequestMapping("/hello")
  public String hello() {
    return "Hello Spring Boot";
  }
}

9、修改配置文件 application.properties

注意:如果只是簡單測試項(xiàng)目只需要添加端口即可,其他數(shù)據(jù)源、緩存、靜態(tài)資源路徑也可以在此配置。

筆者推薦一種配置文件模式:另外新建2個配置文件,一個開發(fā)環(huán)境,一個線上環(huán)境,通過application.properties自由切換

10、啟動項(xiàng)目 選擇Run、Debug啟動

關(guān)于@SpringBootApplication注解說明:@SpringBootApplication開啟了Spring的組件掃描和springboot的自動配置功能,相當(dāng)于將以下三個注解組合在了一起

(1)@Configuration:表名該類使用基于Java的配置,將此類作為配置類

(2)@ComponentScan:啟用注解掃描

(3)@EnableAutoConfiguration:開啟springboot的自動配置功能

訪問項(xiàng)目 http://localhost:8089/hello

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論