简介

Spring Boot 用来简化 Spring 应用开发,约定大于配置,去繁从简,just run 就能创建一个独立的、产品级别的应用。

背景:

J2EE 笨重的开发、繁多的配置、低下的开发效率、复杂的部署流程、第三方技术集成难度大。

解决:

  • “Spring全家桶”时代。
  • Spring Boot -> J2EE 一站式解决方案。
  • Spring Cloud -> 分布式整体解决方案。

优点:

  • 可快速创建独立运行的 Spring 项目以及与主流框架集成。
  • 使用嵌入式的 Servlet 容器,应用无需打成 war 包。
  • starters 自动依赖于版本控制。
  • 大量的自动配置简化了开发,也可修改默认值。
  • 无需配置 XML,无代码生成,开箱即用。
  • 准生产环境的运行时实时监控。
  • 与云计算天然集成。

SpringBoot 官网 | SpringBoot 官方文档SpringBoot-2.1.3.RELEASE 源码下载(其它版本直接修改链接版本号即可)

HelloWorld

编码

1、使用 maven 创建一个 java 项目,依赖如下:

<?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

2、编写 SpringMVC 控制器:

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

3、编写主程序:

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

4、执行主程序:

控制台:

浏览器访问 localhost:8080/test:

效果

5、我们还可以通过 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 为例。

使用

1、新建模块,选中 “Spring Initializr” 项:

2、输入坐标,默认选择 “Maven Project”:

3、可直接勾选要导入的场景:

4、点击“Finish”,完成:

目录结构

默认生成的 SpringBoot 项目:

  • 主程序已经生成好了,我们只需要编写需要的逻辑。
  • resources 文件夹中目录结构:
    static:保存所有的静态资源,例如:js、css、images 等。
    templates:保存所有的模板页面;(SpringBoot 以 jar 包方式嵌入Tomcat,默认不支持 JSP 页面,可使用模板引擎如:freemarker、thymeleaf)。
    application.properties:SpringBoot 应用的配置文件,可以修改一些默认设置。

java框架之SpringBoot(1)-入门的更多相关文章

  1. 【Java框架型项目从入门到装逼】第七节 - 学生管理系统项目搭建

    本次的教程是打算用Spring,SpringMVC以及传统的jdbc技术来制作一个简单的增删改查项目,对用户信息进行增删改查,就这么简单. 1.新建项目 首先,打开eclipse,新建一个web项目. ...

  2. java框架之Spring(1)-入门

    介绍 概述 Spring 是一个开放源代码的设计层面框架,它解决的是业务逻辑层和其他各层的松耦合问题,因此它将面向接口的编程思想贯穿整个系统应用.Spring 是于 2003 年兴起的一个轻量级的 J ...

  3. java框架之MyBatis(1)-入门&动态代理开发

    前言 学MyBatis的原因 1.目前最主流的持久层框架为 Hibernate 与 MyBatis,而且国内公司目前使用 Mybatis 的要比 Hibernate 要多. 2.Hibernate 学 ...

  4. java框架之SpringMVC(1)-入门&整合MyBatis

    前言 SpringMVC简介 SpringMVC 是一个类似于 Struts2 表现层的框架,属于 SpringFramework 的后续产品. 学习SpringMVC的原因 SpringMVC 与 ...

  5. java框架之SpringBoot(3)-日志

    市面上的日志框架 日志抽象层 日志实现 JCL(Jakarta Commons Logging).SLF4J(Simple Logging Facade For Java).JBoss-Logging ...

  6. java框架之SpringBoot(4)-资源映射&thymeleaf

    资源映射 静态资源映射 查看 SpringMVC 的自动配置类,里面有一个配置静态资源映射的方法: @Override public void addResourceHandlers(Resource ...

  7. java框架之SpringBoot(5)-SpringMVC的自动配置

    本篇文章内容详细可参考官方文档第 29 节. SpringMVC介绍 SpringBoot 非常适合 Web 应用程序开发.可以使用嵌入式 Tomcat,Jetty,Undertow 或 Netty ...

  8. java框架之SpringBoot(14)-任务

    使用 maven 创建 SpringBoot 项目,引入 Web 场景启动器. 异步任务 1.编写异步服务类,注册到 IoC 容器: package zze.springboot.task.servi ...

  9. java框架之SpringBoot(15)-安全及整合SpringSecurity

    SpringSecurity介绍 Spring Security 是针对 Spring 项目的安全框架,也是 Spring Boot 底层安全模块默认的技术选型.它可以实现强大的 Web 安全控制.对 ...

随机推荐

  1. Integer.parseInt vs Integer.valueOf

    一直搞不清楚这两个有什么区别.刚才特意查了一下帖子. Integer.parseInt 返回的是 primitive int Integer.valueOf  返回的是 Integer Object ...

  2. 利用Navicate把SQLServer转MYSQL的方法(连数据)

    中文乱码问题:https://pqcc.iteye.com/blog/661640 本次转换需要依赖使用工具Navicat Premium. 首先,将数据库移至本地SQLServer,我试过直接在局域 ...

  3. .NET Core 2.1中的HttpClientFactory最佳实践

    ASP.NET Core 2.1中出现一个新的HttpClientFactory功能, 它有助于解决开发人员在使用HttpClient实例从其应用程序发出外部Web请求时可能遇到的一些常见问题. 介绍 ...

  4. win2003远程桌面怎么切换到多用户?

    怎么用远程桌面切换server2003的多用户的问题?server2003操作系统的远程桌面是多用户的,就是你的机子远程桌面到服务器而其它机子也可以远程桌面,所以往往有时候你看不到原始的桌面的样子,所 ...

  5. [Cassandra] Mutation of <x> bytes is too large for the maxiumum size of <y>

    [Cassandra] Mutation of bytes is too large for the maxiumum size of Q: WARN [SharedPool-Worker-4] 20 ...

  6. 新唐MCU常用的工具软件

    ICP   在电路编程  需要NULINK ISP   在系统编程,可通过串口或USB PINVIEW 可以显示管脚目前的状态.提供keil下或者单独运行两种模式.Keil下进入debug模式后,点击 ...

  7. go关键字之type用法

    1.定义结构体 type Student struct {     name string code int }       2.类型别名 type i int64 var age i = 30   ...

  8. VS2017 配置QT5

    QT安装 1. QT下载 2. 安装过程中,组件的选择(图自https://blog.csdn.net/gaojixu/article/details/82185694) 3. 安装完成 VS2017 ...

  9. 开发环境使用docker 快速启动 单机 RocketMq

    镜像说明 https://cr.console.aliyun.com/?spm=5176.2020520001.1001.8.kpaxIC&accounttraceid=176ddc4e-62 ...

  10. 初识springcloud

    springcloud的基础是springboot,简单地说,就是通过写的springboot应用,使用springcloud集成. 在学习springcloud的过程中,自己的开发环境不能保证和博客 ...