使用idea建立springboot項目

1.爲何要使用springboot

springboot的框架優勢:如下摘自spring官網對springboot的介紹;https://spring.io/projects/spring-bootjava

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

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

使用Spring Boot能夠很容易的建立獨立的,基於生產級別的基於Spring的應用程序,能夠直接運行它。  咱們能夠很容易的使用它集成第三方的依賴,減小了沒必要要的麻煩。大多數Spring Boot應用程序只須要不多的Spring配置。數據庫

Features(特色)springboot

  • Create stand-alone Spring applications 建立獨立的Spring應用程序服務器

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

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

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

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

  • 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 選擇maven建立項目,直接下一步

   

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

 

 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下一章講解啓動類

相關文章
相關標籤/搜索