java框架之SpringBoot(1)-入門

簡介

Spring Boot 用來簡化 Spring 應用開發,約定大於配置,去繁從簡,just run 就能建立一個獨立的、產品級別的應用。css

背景:html

J2EE 笨重的開發、繁多的配置、低下的開發效率、複雜的部署流程、第三方技術集成難度大。java

解決:react

  • 「Spring全家桶」時代。
  • Spring Boot -> J2EE 一站式解決方案。
  • Spring Cloud -> 分佈式總體解決方案。

優勢:git

  • 可快速建立獨立運行的 Spring 項目以及與主流框架集成。
  • 使用嵌入式的 Servlet 容器,應用無需打成 war 包。
  • starters 自動依賴於版本控制。
  • 大量的自動配置簡化了開發,也可修改默認值。
  • 無需配置 XML,無代碼生成,開箱即用。
  • 準生產環境的運行時實時監控。
  • 與雲計算自然集成。

SpringBoot 官網 | SpringBoot 官方文檔SpringBoot-2.1.3.RELEASE 源碼下載(其它版本直接修改連接版本號便可)github

HelloWorld

編碼

一、使用 maven 建立一個 java 項目,依賴以下:web

<?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.3.RELEASE</version>
        <relativePath/>
    </parent>
    <groupId>com.zze.learning</groupId>
    <artifactId>springboot_helloworld</artifactId>
    <version>1.0-SNAPSHOT</version>

    <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>
            <!--這個插件,能夠將應用打包成一個可執行的 jar 包-->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
pom.xml

二、編寫 SpringMVC 控制器:redis

package com.zze.springboot.controller;

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

@Controller
public class TestController {
    @RequestMapping("/test")
    @ResponseBody
    public String test(){
        return "hello world";
    }
}
com.zze.springboot.controller.TestController

三、編寫主程序:spring

package com.zze.springboot;

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

@SpringBootApplication // 標註一個主程序類,說明這是一個 Spring Boot 應用
public class TestApplication {
    public static void main(String[] args) {
        // Spring 應用啓動
        SpringApplication.run(TestApplication.class, args);
    }
}
com.zze.springboot.TestApplication

四、執行主程序:mongodb

控制檯:

瀏覽器訪問 localhost:8080/test:

效果

五、咱們還能夠經過 maven 將程序打成一個 jar 包,直接經過 java 命令啓動:

CMD:


瀏覽器訪問 localhost:8080/test:

效果

這個 HelloWorld 程序也可使用官網幫助生成,點擊使用

探究

pom文件

  • 父項目

    首先,咱們引入了一個父項目:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
        <relativePath/>
    </parent>

     而這個父項目也有一個父項目:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>2.1.3.RELEASE</version>
        <relativePath>../../spring-boot-dependencies</relativePath>
    </parent>

    這個父項目是真正管理 SpringBoot 應用中的全部依賴版本,它能夠稱爲 SpringBoot 的版本管理中心,因此之後咱們導入它管理的依賴是不須要聲明版本的。

  • 場景啓動器

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    該依賴幫咱們導入了 web 模塊正常運行所依賴的組件。

    spring-boot-starter:SpingBoot 場景啓動器。SpringBoot 將全部功能場景都抽取出來,作成一個個 starter (場景啓動器),只須要在項目中引入這些 starter 相關場景的全部依賴都會導入進來,要使用什麼功能就導入什麼場景啓動器。下面是 SpringBoot 提供的一些場景啓動器:

    Name Description Pom

    spring-boot-starter

    Core starter, including auto-configuration support, logging and YAML

    Pom

    spring-boot-starter-activemq

    Starter for JMS messaging using Apache ActiveMQ

    Pom

    spring-boot-starter-amqp

    Starter for using Spring AMQP and Rabbit MQ

    Pom

    spring-boot-starter-aop

    Starter for aspect-oriented programming with Spring AOP and AspectJ

    Pom

    spring-boot-starter-artemis

    Starter for JMS messaging using Apache Artemis

    Pom

    spring-boot-starter-batch

    Starter for using Spring Batch

    Pom

    spring-boot-starter-cache

    Starter for using Spring Framework’s caching support

    Pom

    spring-boot-starter-cloud-connectors

    Starter for using Spring Cloud Connectors which simplifies connecting to services in cloud platforms like Cloud Foundry and Heroku

    Pom

    spring-boot-starter-data-cassandra

    Starter for using Cassandra distributed database and Spring Data Cassandra

    Pom

    spring-boot-starter-data-cassandra-reactive

    Starter for using Cassandra distributed database and Spring Data Cassandra Reactive

    Pom

    spring-boot-starter-data-couchbase

    Starter for using Couchbase document-oriented database and Spring Data Couchbase

    Pom

    spring-boot-starter-data-couchbase-reactive

    Starter for using Couchbase document-oriented database and Spring Data Couchbase Reactive

    Pom

    spring-boot-starter-data-elasticsearch

    Starter for using Elasticsearch search and analytics engine and Spring Data Elasticsearch

    Pom

    spring-boot-starter-data-jdbc

    Starter for using Spring Data JDBC

    Pom

    spring-boot-starter-data-jpa

    Starter for using Spring Data JPA with Hibernate

    Pom

    spring-boot-starter-data-ldap

    Starter for using Spring Data LDAP

    Pom

    spring-boot-starter-data-mongodb

    Starter for using MongoDB document-oriented database and Spring Data MongoDB

    Pom

    spring-boot-starter-data-mongodb-reactive

    Starter for using MongoDB document-oriented database and Spring Data MongoDB Reactive

    Pom

    spring-boot-starter-data-neo4j

    Starter for using Neo4j graph database and Spring Data Neo4j

    Pom

    spring-boot-starter-data-redis

    Starter for using Redis key-value data store with Spring Data Redis and the Lettuce client

    Pom

    spring-boot-starter-data-redis-reactive

    Starter for using Redis key-value data store with Spring Data Redis reactive and the Lettuce client

    Pom

    spring-boot-starter-data-rest

    Starter for exposing Spring Data repositories over REST using Spring Data REST

    Pom

    spring-boot-starter-data-solr

    Starter for using the Apache Solr search platform with Spring Data Solr

    Pom

    spring-boot-starter-freemarker

    Starter for building MVC web applications using FreeMarker views

    Pom

    spring-boot-starter-groovy-templates

    Starter for building MVC web applications using Groovy Templates views

    Pom

    spring-boot-starter-hateoas

    Starter for building hypermedia-based RESTful web application with Spring MVC and Spring HATEOAS

    Pom

    spring-boot-starter-integration

    Starter for using Spring Integration

    Pom

    spring-boot-starter-jdbc

    Starter for using JDBC with the HikariCP connection pool

    Pom

    spring-boot-starter-jersey

    Starter for building RESTful web applications using JAX-RS and Jersey. An alternative to spring-boot-starter-web

    Pom

    spring-boot-starter-jooq

    Starter for using jOOQ to access SQL databases. An alternative to spring-boot-starter-data-jpa or spring-boot-starter-jdbc

    Pom

    spring-boot-starter-json

    Starter for reading and writing json

    Pom

    spring-boot-starter-jta-atomikos

    Starter for JTA transactions using Atomikos

    Pom

    spring-boot-starter-jta-bitronix

    Starter for JTA transactions using Bitronix

    Pom

    spring-boot-starter-mail

    Starter for using Java Mail and Spring Framework’s email sending support

    Pom

    spring-boot-starter-mustache

    Starter for building web applications using Mustache views

    Pom

    spring-boot-starter-oauth2-client

    Starter for using Spring Security’s OAuth2/OpenID Connect client features

    Pom

    spring-boot-starter-oauth2-resource-server

    Starter for using Spring Security’s OAuth2 resource server features

    Pom

    spring-boot-starter-quartz

    Starter for using the Quartz scheduler

    Pom

    spring-boot-starter-security

    Starter for using Spring Security

    Pom

    spring-boot-starter-test

    Starter for testing Spring Boot applications with libraries including JUnit, Hamcrest and Mockito

    Pom

    spring-boot-starter-thymeleaf

    Starter for building MVC web applications using Thymeleaf views

    Pom

    spring-boot-starter-validation

    Starter for using Java Bean Validation with Hibernate Validator

    Pom

    spring-boot-starter-web

    Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container

    Pom

    spring-boot-starter-web-services

    Starter for using Spring Web Services

    Pom

    spring-boot-starter-webflux

    Starter for building WebFlux applications using Spring Framework’s Reactive Web support

    Pom

    spring-boot-starter-websocket

    Starter for building WebSocket applications using Spring Framework’s WebSocket support

    Pom

主程序類

package com.zze.springboot;

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

@SpringBootApplication // 標註一個主程序類,說明這是一個 Spring Boot 應用
public class TestApplication {
    public static void main(String[] args) {
        // Spring 應用啓動
        SpringApplication.run(TestApplication.class, args);
    }
}

@SpringBootApplication :標註在某個類上說明這個類是 SpringBoot 的主配置類,SpringBoot 就應該運行這個類的 main 方法來啓動 SpringBoot 應用。查看它,發現它實際上是一個組合註解:

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(
    excludeFilters = {@Filter(
    type = FilterType.CUSTOM,
    classes = {TypeExcludeFilter.class}
), @Filter(
    type = FilterType.CUSTOM,
    classes = {AutoConfigurationExcludeFilter.class}
)}
)
public @interface SpringBootApplication {
  • @SpringBootConfiguration :標註在某個類上,表示這是一個 SpringBoot 的配置類。而它也是一個組合註解:

    @Target({ElementType.TYPE})
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    @Configuration
    public @interface SpringBootConfiguration {
    • @Configuration :Spring 配置類上來標註這個註解。它實際上是容器中的一個組件:

      @Target({ElementType.TYPE})
      @Retention(RetentionPolicy.RUNTIME)
      @Documented
      @Component
      public @interface Configuration {
@EnableAutoConfiguration :開啓自動配置功能。之前咱們須要配置的部分,SpringBoot 幫咱們自動配置。查看它:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@AutoConfigurationPackage
@Import(AutoConfigurationImportSelector.class)
public @interface EnableAutoConfiguration {
  • @AutoConfigurationPackage :自動配置包註解。
    @Target(ElementType.TYPE)
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    @Inherited
    @Import(AutoConfigurationPackages.Registrar.class)
    public @interface AutoConfigurationPackage {
    • @Import(AutoConfigurationPackages.Registrar.class) :Spring 底層註解,給容器中導入組件。導入的組件由 AutoConfigurationPackages.Registrar.class 決定,使用這個類會將所標識類(即: com.zze.springboot.TestApplication 類)所在包及子包下的全部類掃描到 Spring 容器。

      @Target({ElementType.TYPE})
      @Retention(RetentionPolicy.RUNTIME)
      @Documented
      public @interface Import {
  • @Import(AutoConfigurationImportSelector.class) :Spring 底層註解,給容器中導入組件。 AutoConfigurationImportSelector.class 會將要導入的組件以全類名方式返回,這些組件就會被添加到容器中。最終會給容器中導入不少自動配置類,這些自動配置類的做用就是給容器中導入這個場景須要的全部組件,並配置好這些組件。有了自動配置類,免去了咱們手動編寫配置注入功能組件等工做。這些自動配置類全路徑名放在哪裏呢?查看源碼會發現,這些類的全路徑名是從類路徑下 META-INF/spring.factories 中讀取。

    # Initializers
    org.springframework.context.ApplicationContextInitializer=\
    org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer,\
    org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener
    
    # Application Listeners
    org.springframework.context.ApplicationListener=\
    org.springframework.boot.autoconfigure.BackgroundPreinitializer
    
    # Auto Configuration Import Listeners
    org.springframework.boot.autoconfigure.AutoConfigurationImportListener=\
    org.springframework.boot.autoconfigure.condition.ConditionEvaluationReportAutoConfigurationImportListener
    
    # Auto Configuration Import Filters
    org.springframework.boot.autoconfigure.AutoConfigurationImportFilter=\
    org.springframework.boot.autoconfigure.condition.OnBeanCondition,\
    org.springframework.boot.autoconfigure.condition.OnClassCondition,\
    org.springframework.boot.autoconfigure.condition.OnWebApplicationCondition
    
    # Auto Configure
    org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
    org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration,\
    org.springframework.boot.autoconfigure.aop.AopAutoConfiguration,\
    org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration,\
    org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration,\
    org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration,\
    org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration,\
    org.springframework.boot.autoconfigure.cloud.CloudServiceConnectorsAutoConfiguration,\
    org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration,\
    org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration,\
    org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,\
    org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration,\
    org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveDataAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveRepositoriesAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.cassandra.CassandraRepositoriesAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.couchbase.CouchbaseDataAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveDataAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveRepositoriesAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.couchbase.CouchbaseRepositoriesAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchRepositoriesAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.jdbc.JdbcRepositoriesAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.ldap.LdapRepositoriesAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.mongo.MongoReactiveDataAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.mongo.MongoReactiveRepositoriesAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.neo4j.Neo4jDataAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.neo4j.Neo4jRepositoriesAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.solr.SolrRepositoriesAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.redis.RedisReactiveAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration,\
    org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration,\
    org.springframework.boot.autoconfigure.elasticsearch.jest.JestAutoConfiguration,\
    org.springframework.boot.autoconfigure.elasticsearch.rest.RestClientAutoConfiguration,\
    org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration,\
    org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration,\
    org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration,\
    org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration,\
    org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration,\
    org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration,\
    org.springframework.boot.autoconfigure.hazelcast.HazelcastJpaDependencyAutoConfiguration,\
    org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration,\
    org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration,\
    org.springframework.boot.autoconfigure.influx.InfluxDbAutoConfiguration,\
    org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration,\
    org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration,\
    org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration,\
    org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
    org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration,\
    org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration,\
    org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration,\
    org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\
    org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration,\
    org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration,\
    org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration,\
    org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration,\
    org.springframework.boot.autoconfigure.jms.artemis.ArtemisAutoConfiguration,\
    org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration,\
    org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration,\
    org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration,\
    org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration,\
    org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration,\
    org.springframework.boot.autoconfigure.ldap.embedded.EmbeddedLdapAutoConfiguration,\
    org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration,\
    org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,\
    org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration,\
    org.springframework.boot.autoconfigure.mail.MailSenderValidatorAutoConfiguration,\
    org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration,\
    org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,\
    org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration,\
    org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration,\
    org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\
    org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration,\
    org.springframework.boot.autoconfigure.reactor.core.ReactorCoreAutoConfiguration,\
    org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration,\
    org.springframework.boot.autoconfigure.security.servlet.SecurityRequestMatcherProviderAutoConfiguration,\
    org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration,\
    org.springframework.boot.autoconfigure.security.servlet.SecurityFilterAutoConfiguration,\
    org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration,\
    org.springframework.boot.autoconfigure.security.reactive.ReactiveUserDetailsServiceAutoConfiguration,\
    org.springframework.boot.autoconfigure.sendgrid.SendGridAutoConfiguration,\
    org.springframework.boot.autoconfigure.session.SessionAutoConfiguration,\
    org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientAutoConfiguration,\
    org.springframework.boot.autoconfigure.security.oauth2.client.reactive.ReactiveOAuth2ClientAutoConfiguration,\
    org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration,\
    org.springframework.boot.autoconfigure.security.oauth2.resource.reactive.ReactiveOAuth2ResourceServerAutoConfiguration,\
    org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration,\
    org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration,\
    org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration,\
    org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\
    org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration,\
    org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration,\
    org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,\
    org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration,\
    org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration,\
    org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration,\
    org.springframework.boot.autoconfigure.web.reactive.ReactiveWebServerFactoryAutoConfiguration,\
    org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration,\
    org.springframework.boot.autoconfigure.web.reactive.error.ErrorWebFluxAutoConfiguration,\
    org.springframework.boot.autoconfigure.web.reactive.function.client.ClientHttpConnectorAutoConfiguration,\
    org.springframework.boot.autoconfigure.web.reactive.function.client.WebClientAutoConfiguration,\
    org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration,\
    org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration,\
    org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration,\
    org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration,\
    org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration,\
    org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration,\
    org.springframework.boot.autoconfigure.websocket.reactive.WebSocketReactiveAutoConfiguration,\
    org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration,\
    org.springframework.boot.autoconfigure.websocket.servlet.WebSocketMessagingAutoConfiguration,\
    org.springframework.boot.autoconfigure.webservices.WebServicesAutoConfiguration,\
    org.springframework.boot.autoconfigure.webservices.client.WebServiceTemplateAutoConfiguration
    
    # Failure analyzers
    org.springframework.boot.diagnostics.FailureAnalyzer=\
    org.springframework.boot.autoconfigure.diagnostics.analyzer.NoSuchBeanDefinitionFailureAnalyzer,\
    org.springframework.boot.autoconfigure.jdbc.DataSourceBeanCreationFailureAnalyzer,\
    org.springframework.boot.autoconfigure.jdbc.HikariDriverConfigurationFailureAnalyzer,\
    org.springframework.boot.autoconfigure.session.NonUniqueSessionRepositoryFailureAnalyzer
    
    # Template availability providers
    org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider=\
    org.springframework.boot.autoconfigure.freemarker.FreeMarkerTemplateAvailabilityProvider,\
    org.springframework.boot.autoconfigure.mustache.MustacheTemplateAvailabilityProvider,\
    org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAvailabilityProvider,\
    org.springframework.boot.autoconfigure.thymeleaf.ThymeleafTemplateAvailabilityProvider,\
    org.springframework.boot.autoconfigure.web.servlet.JspTemplateAvailabilityProvider
    spring-boot-autoconfigure-2.1.3.RELEASE.jar!/META-INF/spring.factories

    J2EE的總體解決方案和自動配置都在 spring-boot-autoconfigure-2.1.3.RELEASE.jar 中。

Spring Initializr

IDE 都支持使用 Spring 的項目建立嚮導快速建立一個 SpringBoot 項目(需聯網環境下)。下面以 IDEA 爲例。

使用

一、新建模塊,選中 「Spring Initializr」 項:

二、輸入座標,默認選擇 「Maven Project」:

三、可直接勾選要導入的場景:

四、點擊「Finish」,完成:

目錄結構

默認生成的 SpringBoot 項目:

  • 主程序已經生成好了,咱們只須要編寫須要的邏輯。
  • resources 文件夾中目錄結構:
    static:保存全部的靜態資源,例如:js、css、images 等。
    templates:保存全部的模板頁面;(SpringBoot 以 jar 包方式嵌入Tomcat,默認不支持 JSP 頁面,可以使用模板引擎如:freemarker、thymeleaf)。
    application.properties:SpringBoot 應用的配置文件,能夠修改一些默認設置。
相關文章
相關標籤/搜索