使用idea創建springboot項目


1.為什么要使用springboot

springboot的框架優點:以下摘自spring官網對springboot的介紹;https://spring.io/projects/spring-boot

 Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run".

We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.

使用Spring Boot可以很容易的創建獨立的,基於生產級別的基於Spring的應用程序,可以直接運行它。  我們可以很容易的使用它集成第三方的依賴,減少了不必要的麻煩。大多數Spring Boot應用程序只需要很少的Spring配置。

Features(特點)

  • Create stand-alone Spring applications 創建獨立的Spring應用程序

  • Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)    直接嵌入了Tomcat,Jetty或Undertow(無需部署WAR包了)

  • Provide opinionated 'starter' dependencies to simplify your build configuration  提供了初始化的依賴,簡化了配置

  • Automatically configure Spring and 3rd party libraries whenever possible  自動配置spring和第三方庫

  • Provide production-ready features such as metrics, health checks and externalized configuration  提供生產環境的一些功能,例如指標,運行狀況檢查和外部配置

  • Absolutely no code generation and no requirement for XML configuration  完全沒有代碼生成,也不需要XML配置

優點:

(以下為網友總結的,其實和官網所說的是一樣的,只是更加容易理解):

  • 使用Java或Groovy開發基於Spring的應用程序非常容易。
  • 它減少了大量的開發時間並提高了生產力。
  • 它避免了編寫大量的樣板代碼,注釋和XML配置。
  • Spring Boot應用程序與其Spring生態系統(如Spring JDBC,Spring ORM,Spring Data,Spring Security等)集成非常容易。
  • 它遵循“自用默認配置”方法,以減少開發工作量。
  • 它提供嵌入式HTTP服務器,如Tomcat,Jetty等,以開發和測試Web應用程序非常容易。
  • 它提供CLI(命令行界面)工具從命令提示符,非常容易和快速地開發和測試Spring Boot(Java或Groovy)應用程序。
  • 它提供了許多插件來開發和測試Spring啟動應用程序非常容易使用構建工具,如Maven和Gradle。
  • 它提供了許多插件,以便與嵌入式和內存數據庫工作非常容易。

缺點

  • 將現有或傳統的Spring Framework項目轉換為Spring Boot應用程序是一個非常困難和耗時的過程。它僅適用於全新Spring項目。

2.搭建springboot項目

1.file->new->project 選擇Spring Initializr創建項目,直接下一步

   

2.填寫groupid、artifactid、version等信息,然后點擊下一步

 

 點擊下一步

 

 左邊根據需要配置,不需要直接點擊下一步即完成sprint boot項目搭建

 

 

 

 3.然后在創建的項目的pom中添加springboot的依賴

 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

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

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

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

4.使用spring官網創建springboot項目

官網地址:https://start.spring.io/

填寫自己創建項目的信息,然后點擊generate進行生成,會生成一個demo.zip的包,解壓后,使用idea導入即可

 

 

springboot下一章講解啟動類

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM