史上最全 SpringBoot 1.3.0.RELEASE 版本特性介绍(全文英译版)

Spring Boot v1.3.0.RELEASE

参考链接:https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.3-Release-Notes#new-and-noteworthy

Spring Boot 1.3.0 Release Notes

Upgrading from Spring Boot 1.2

Deprecations from Spring Boot 1.2

在Spring Boot 1.2中弃用的类、方法和属性已经在这个版本中删除了。请确保在升级之前没有调用已弃用的方法。

Jackson

Spring Boot 1.2向应用程序上下文中的每个ObjectMapper注册了任何Jackson Module bean。这使得不可能完全控制ObjectMapper bean的模块。Spring Boot 1.3将只向使用自动配置的Jackson2ObjectMapperBuilder创建或配置的ObjectMapper 注册Jackson Module bean。这使得模块配置的行为与Spring Boot的其他Jackson配置一致。

Logging

Spring specific configuration

为了防止双重初始化,现在可以使用Spring特定的日志配置文件。建议(虽然不是必需的)重命名任何缺省日志配置文件,以使用-spring后缀。例如,logback.xml将更改为logback-spring.xml。

Initialization failures

在Spring Boot 1.2中,如果您使用 logging.config 指定了一个定制的日志配置文件且文件不存在时,它将静默地退回到使用默认配置。Spring Boot 1.3由于缺少文件而失败。类似地,如果您提供了一个格式错误的自定义日志配置文件,那么Spring Boot 1.2将退回到它的默认配置。Spring Boot 1.3失败并向System.err报告配置问题。

Spring HATEOAS

spring.hateoas.apply-to-primary-object-mapper属性已经被删除,因为Spring HATEOAS自动配置已经被重新修改,这样它就不再影响上下文的主ObjectMapper。它已经被一个名为spring.hateoas.use-hal-as-default-json-media-type的属性所取代,它控制Spring HATEOAS HTTP消息转换器除了处理application/hal+json请求外,还处理application/json请求。

Security for the /health endpoint

对actuator /health端点上可见的信息的安全设置进行了一些调整,以提供更好的一致性。有关完整详细信息,请参阅参考指南中的HTTP运行状况端点访问限制(HTTP health endpoint access restrictions)一节。

HTTP response compression

Spring Boot 1.2支持Tomcat用户的本机响应压缩,或者使用Jetty的GZipFilter对Jetty、Tomcat和Undertow用户进行压缩。受Jetty团队弃用gzip过滤器的激励,Spring Boot 1.3用在所有三个嵌入式容器中支持本地响应压缩来取代它。结果是server.tomcat.compression. 和 spring.http.gzip. 属性不再支持。应该使用新的server.compression.* 属性。

Tomcat session storage

默认情况下,tomcat不再将会话数据保存在/tmp中。如果希望使用Tomcat使用持久会话,请设置server.session.persistent属性为true。server.session.store-dir 可以使用将文件保存在特定的位置。

Jetty JSPs

spring-boot-starter-jetty“Starter POM”不再包括org.eclipse.jetty:jetty-jsp。如果您将Jetty与JSPs一起使用,那么您现在需要自己直接添加这个依赖项。

MVC Stacktrace output

当Spring MVC呈现错误响应时,不会包含Stacktrace信息。如果你想要Spring Boot 1.2行为设置 error.include-stacktrace到on-trace-param。

Thymeleaf’s Spring Security integration

由于升级到了Spring Security 4, Spring Boot 1.3也升级了Thymeleaf的Spring Security支持的依赖项管理和自动配置。新工件的坐标是:org.thymeleaf.extras:thymeleaf-extras-springsecurity4。请相应地更新您的pom.xml或build.gradle。

Missing /templates folder errors

当找不到/templates文件夹时,Spring Boot 应用程序不再无法启动。如果您正在使用受支持的模板技术,而您忘记添加/templates,那么现在会记录一个警告。

Groovy templating

GroovyTemplateProperties类现在扩展了AbstractTemplateViewResolverProperties并提供了额外的配置选项。如果您当前定义了一个 prefix.spring.groovy.template.prefix属性要定义自定义资源位置,您应该将其重命名为prefix.spring.groovy.resource-loader-location。

Auto-configuration order

Spring Boot不再使用@Order来管理自动配置类之间的订单,请使用@AutoconfigureOrder代替。还要注意,您可以使用@AutoconfigureBefore和@AutoconfigureAfter来指定针对特定自动配置类的顺序。

Gradle plugin

bootRun resources

当使用bootRun时,Spring Boot Gradle插件不再将src/main/resources直接添加到类路径中。如果你想要实时的就地编辑,我们建议使用Devtools。如果你想恢复Spring Boot 1.2的行为,可以在你的gradle构建中设置addResources属性。

Dependency management

Spring Boot的gradle插件在这个版本中已经更新为使用依赖管理插件(dependency management plugin)。大多数用户应该不会受到这个变化的影响,但是那些使用versionManagement配置来应用他们自己的受祝福的版本的用户将不得不更新他们的构建脚本。

新的插件允许您使用Maven bom,而不需要属性文件来配置版本管理。例如:

Application plugin

默认情况下,Spring Boot Gradle插件将不再应用Gradle的应用插件(application plugin)。如果你想使用这个应用插件,你必须在build.gradle中应用它。

如果你不需要应用插件提供的功能,但使用了它的mainClassName或applicationDefaultJvmArgs属性,那么你需要对build.gradle做一些小的更新。

现在应该使用Spring Boot扩展上的mainClass属性来配置main类,例如:

springBoot {

    mainClass = 'com.example.YourApplication'

}

applicationDefaultJvmArgs 现在应该在你的项目的ext块中配置,例如:

ext {

    applicationDefaultJvmArgs = [ '-Dcom.example.property=true' ]

}

如果你正在使用应用程序插件的run任务的main属性来配置你的项目的main类,你应该把这个配置移到bootRun任务中:

bootRun {

    main = com.example.YourApplication

}

Maven plugin

spring-boot:run resources

当使用spring-boot:run时,Spring Boot Maven插件不再将src/main/resources直接添加到类路径中。如果你想要实时的就地编辑,我们建议使用Devtools。如果希望恢复Spring Boot 1.2的行为,可以在pom.xml中设置addResources属性。

Maven resources filtering

如果您使用spring-boot-starter-parent, Maven令牌现在只使用@ 进行过滤。这样可以防止配置中的任何Spring占位符(例如${foo})被构建扩展。

具体来说,如果你还在使用标准格式(即${project.version}),请迁移它们(@project.version@)或重写maven-resources-plugin配置。

CLI dependency management

Spring Boot 1.3现在支持使用Maven bom来配置其依赖项管理,而不是基于属性文件的元数据。应该使用@DependencyManagementBom来代替@GrabMetadata来提供bom的坐标,例如@DependencyManagementBom("io.spring.platform:platform-bom:1.1.2.RELEASE")。

Property renames

下面的application.properties键被重命名以提高一致性:

spring.view. to spring.mvc.view.

spring.pidfile to spring.pid.file

error.path to server.error.path

server.session-timeout to server.session.timeout

servet.tomcat.accessLogEnabled to server.tomcat.accesslog.enabled

servet.tomcat.accessLogPattern to server.tomcat.accesslog.pattern

servet.undertow.accessLogDir to server.undertow.accesslog.dir

servet.undertow.accessLogEnabled to server.undertow.accesslog.enabled

servet.undertow.accessLogPattern to server.undertow.accesslog.pattern

spring.oauth2. to security.oauth2.

server.tomcat.compression and spring.http.gzip to server.compression.*

prefix.spring.groovy.template.prefix to prefix.spring.groovy.resource-loader-location

Dependencies

Spring 4.2

pring Boot 1.3需要Spring Framework 4.2或更高版本,与以前的版本不兼容。

Spring Security 4.0

Spring Boot 1.3使用Spring Security 4.0。有关从3.2迁移的信息,请参阅Spring Security文档-Spring Security documentation 。

New and Noteworthy

Tip Check the configuration changelog for a complete overview of the changes in configuration.

Version Updates

Spring Boot 1.3构建于Spring Framework 4.2之上,并且需要Spring Framework 4.2。该版本已经升级了几个第三方依赖项。本版本没有对Tomcat或Jetty版本进行重大升级。

Developer Tools

Spring Boot 1.3包含了一个新的spring-boot-devtools模块,旨在改善开发时间体验。该模块提供了:

Sensible property defaults (for example disabling template caches)

Automatic application restarts

LiveReload support

Remote development support (including remote updates and remote debug via an HTTP tunnel).

Persistent HTTP sessions across restarts

See the updated documentation for more information.

Caching Auto-configuration

自动配置现在提供了以下缓存技术:

EhCache

Hazelcast

Infinispan

Any compliant JCache (JSR 107) implementation

Redis

Guava

此外,还支持简单的基于内存中的映射缓存。当您的应用程序@Configuration被注解为@EnableCaching时,缓存将自动配置。缓存统计信息现在也公开为执行器端点(如果底层技术允许的话)。

For complete details see the updated documentation.

Fully executable JARs and service support

Spring Boot Maven和Gradle插件现在可以为Linux/Unix操作系统生成完整的可执行文件。此外,您现在可以轻松地以安装这些jar作为init.d或systemd服务。运行一个完全可执行的JAR就像输入一样简单:

$ ./myapp.jar

并且安装它作为 init.d 服务:

$ sudo link -s /var/myapp/myapp.jar /etc/init.d/myapp

Additional information is available in the reference documentation.

Cassandra Support

自动配置现在为Cassandra提供。See the reference documentation for details.

OAuth2 Support

现在可以使用@EnableAuthorizationServer和@EnableResourceServer快速创建OAuth2授权和资源服务器。此外,@EnableOAuth2Client允许您的应用程序充当OAuth2客户端。详细信息请参见《参考指南》中“已大修的安全(security section of the reference guide)”部分。

Spring Session

有了Spring Session和Spring Data Redis的类路径,web应用程序将自动配置到Redis中存储用户会话。See the accompanying sample for more information。

jOOQ Support

现在为 jOOQ 提供了自动配置。你可以@Autowire一个jOOQ DSLContext直接到你的Spring Beans来创建类型安全的数据库查询。通过spring.jooq.* 应用属性支持额外的定制。

See the "Using jOOQ" section of the reference documentation for details.

SendGrid

现在为SendGrid电子邮件传递服务提供了自动配置。

Artemis auto-configuration

Apache Artemis成立于2015年,HornetQ被捐赠给Apache基金会。从Spring Boot 1.3开始,Apache Artemis就得到了完全支持,可以像HornetQ一样使用它。如果你要迁移到Artemis,你应该重命名任何spring.hornetq. 属性为spring.artemis . 。

Validation "Starter POM"

一个新的spring-boot-starter-validation“starter POM”现在可用来提供bean验证(JSR 303)支持。

Support for @WebServlet, @WebFilter and @WebListener

当使用嵌入式servlet容器时,@WebServlet、@WebFilter和@WebListener注解类的自动注册现在可以使用@ServletComponentScan来启用。

Spring resource chains

You can now configure basic aspects of Spring’s ResourceChainRegistration via application properties. This allows you to create unique resource names so that you can implement cache busting. The spring.resources.chain.strategy.content. properties can be used to configure fingerprinting based on the content of the resource; and spring.resources.chain.strategy.fixed. properties can be used if you want to use a "fixed version" for your fingerprint.

现在可以通过应用程序属性配置Spring的ResourceChainRegistration的基本方面。这允许你创建唯一的资源名,这样你就可以实现缓存销毁。spring.resources.chain.strategy.content. 属性可用于配置基于资源内容的指纹;而且spring.resources.chain.strategy.fixed. 属性可以被使用,如果您想使用指纹的“固定版本”。

JDBC

Spring Boot现在会自动从以下数据库的JDBC URL中推断驱动程序类名:

DB2

Firebird

Teradata

DataSource type

自动配置使用的连接池现在可以通过spring.datasource.type指定key。

H2 Web Console

添加了H2的web控制台(H2’s web console)的自动配置。当您使用Spring Boot的开发人员工具时,添加一个对com.h2database:h2的依赖项到您的web应用程序是启动所需的全部。Please see the documentation for further information。

Embedded MongoDB

已添加了嵌入式MongoDB(Embedded MongoDB)的自动配置。依赖于de.flapdoodle.embed:de.flapdoodle.embed.mongo是开始的必要条件。配置,比如要使用的Mongo版本,可以通过application.properties来控制。请参阅文档( documentation )获取更多信息。

ANSI color banner.txt files

现在可以在banner.txt文件中使用ANSI占位符来生成颜色输出。${Ansi.}, ${AnsiColor.}, ${AnsiBackground.}或 ${AnsiStyle.} 属性将被展开。例如:

${AnsiColor.BRIGHT_GREEN}My Application

${AnsiColor.BRIGHT_YELLOW}${application.formatted-version}${AnsiColor.DEFAULT}

Default profile application.properties

当没有特定的概要文件激活时,现在在加载application.properties (and application.yml) 文件时考虑-default后缀。当您使用概要文件来指示部署环境时,这可能会很有帮助,例如:

Application arguments

您现在可以实现ApplicationRunner接口,作为CommandLineRunner的替代方案。它以相同的方式工作,但是提供了一个ApplicationArguments接口,而不是String[]。如果需要访问应用程序参数,还可以直接将ApplicationArguments注入到任何现有bean中。

ApplicationArguments接口为访问“option”和“non-option”参数提供了方便的方法。例如:

See Accessing application arguments for details.

Logging

Log Patterns

logging.pattern.console和logging.pattern.file属性现在可以直接从application.properties中指定日志记录模式。如果您只想定制模式,而不再需要定义自己的log*.xml文件,那么这将非常方便。

Jar details in stacktraces

如果您使用的是logback或log4j2,我们现在包含了关于堆栈跟踪中每个类加载位置的信息(可以通过logging.exception-conversion-word定制)。

Log4J 2 Output

Log4J 2的默认输出得到了改进,现在与Logback产生的输出类似。

Tomcat access logs

Tomcat访问日志有更好的自定义:现在可以通过配置自定义目录和文件prefix/suffix。

Logback extensions

Spring Boot 1.3支持一些可以在您的logback配置文件中使用的新标记。要使用这些标记,首先需要将任何logback.xml配置重命名为logback-spring.xml。重命名配置文件后,可以使用以下标记。

See the Logback extensions section of the reference documentation for more details.

HTTP Sessions

Persistent sessions

在应用程序停止时更新Tomcat、Jetty和Undertow以序列化会话数据,并在应用程序重启时再次加载会话数据。持续性会话是可选的;可以在ConfigurableEmbeddedServletContainer上设置persistentSession,也可以使用属性server.session.persistent=true (Devtools默认启用持久会话)。

可以使用server.session.store-dir属性指定保存持久会话数据的位置。

Advanced HTTP Session configuration

现在为会话配置提供了其他属性。您可以使用server.session.*属性设置“tracking modes”和“cookie”细节。

X-Forwarded-For header support

X-Forwarded-For头部支持现在包括了Jetty和Undertow。Tomcat支持也被刷新,以便单个server.use-forward-headers 属性可以设置为true,如果X-Forwarded-For headers 应该被尊重。Spring Boot将检测部署到Cloud Foundry或Heroku,并自动启用支持。

Configuration properties

如果您在bean上使用@ConfigurationProperties,那么您不再需要在Spring Boot自动配置配置时将@EnableConfigurationProperties添加到配置中。与前面一样,您可以要求Spring使用@EnableConfigurationProperties的值属性或使用常规的@Bean定义为您的@ConfigurationProperties类创建一个bean。

Configuration properties conversion

如果您需要对某些配置键进行自定义类型转换,但没有使用自定义ConversionService (使用bean id converonservice),那么现在需要限定Converter bean与@ConfigurationPropertiesBinding一起使用,因为我们不再查找所有Converter bean。

Messaging

JMS和Rabbit端点都可以通过配置轻松禁用。如果不存在,则创建的默认容器工厂也可以通过配置进行定制。

Internationalization

自动配置的MessageSource实例的fallbackToSystemLocale标志现在可以通过spring.messages.fallback-to-system-locale配置key。

Auto-configuration

自动配置报告现在有一个额外的部分叫做“无条件类”。它列出了没有任何类级别条件的自动配置类,即该类将始终是应用程序配置的一部分。它现在还列出了通过@SpringBootApplication(exclude=…)或@EnableAutoConfiguration(exclude=…)手动排除的配置。

现在也可以通过spring.autoconfigure.excludes属性排除自动配置类。类似地,希望有选择地导入某些自动配置类的测试可以使用新的@ ImportAutoConfiguration注解。

MVC Error handling

这个error.include-stacktrace属性现在可以用来确定何时应该在MVC错误响应中包含堆栈跟踪属性。选项是never、always或on-trace-param (never是默认选项)。

Actuator Metrics

spring-boot-actuator指标支持已经扩展到支持导出和聚合。此外,现在提供了Java 8特有的GaugeService和CounterService实现(并在可能时使用),它们提供了更好的性能。

See the extended metrics documentation for details.

Additional Health Indicators

现在提供了额外的HealthIndicators并自动配置:

Elasticsearch

Email

JMS

New actuator endpoints

在Spring Boot 1.3中添加了以下额外的执行器端点:

CORS support for actuator endpoints

执行器的端点现在支持CORS。默认情况下,支持是禁用的,但可以通过配置endpoints.cors.allowed-origins来启用。

Regex support for /env and /metrics

现在可以使用正则表达式来过滤/env和/metrics执行器端点。 例如 http://localhost:8080/metrics/.root.。

Hypermedia for MVC actuator endpoints

当您的类路径上有Spring HATEOAS时(例如通过spring-boot-starter-hateoas),执行器HTTP端点现在可以通过超媒体链接得到增强。一个新的“发现页面”还提供了指向所有执行器端点的链接。如果webjar在类路径上,HAL browser也提供了支持。

See the "Hypermedia for MVC Endpoints" reference section for more details.

Actuator docs endpoint

Spring Boot 1.3提供了一个新的spring-boot-actuator-docs 模块,它允许将actuator文档嵌入到应用程序中。一旦模块在类路径上,就可以点击/docs来获取有关执行器端点的信息,包括每个端点返回的数据示例。

Disabling health indicators

现在可以通过management.health.defaults.enabled属性轻松禁用所有默认运行状况指示器。

TraceWebFilter options

执行器TraceWebFilter(用于跟踪HTTP请求/响应详细信息)现在可以记录更多信息。使用management.trace.include属性配置您想要包含的选项(请参阅TraceProperties.Include 枚举)。

Maven Support

Maven start/stop support and admin features

Maven插件现在包含了开始和停止目标。这些功能可以在不阻塞Maven的情况下启动应用程序(允许其他目标对应用程序进行操作)。这种技术通常用于从Maven启动集成测试。

这项工作的一个副产品是添加了一个新的SpringApplicationAdminMXBean接口,该接口(在启用时)允许通过JMX控制Spring Boot 应用程序。

Profile activation

spring-boot-maven-plugin现在包含了一个profiles属性,可以与spring-boot:run一起使用。您可以在pom.xml中配置配置文件或使用 -Drun.profiles在命令行。See theupdated plugin documentation for details。

Ant Support

Spring Boot现在包含了一个AntLib模块来帮助您从Ant创建可执行jar。请参阅参考文档中的“Spring Boot AntLib module模块”一节。

Configuration property meta-data updates

META-INF/spring-configuration-metadata.json 文件格式已经更新,以支持新的弃用和提示属性。IDE开发人员可以使用提示来提供更好的内容辅助支持。弃用允许弃用和替换键(如果有的话)。这些信息可以通过在属性的getter上添加@DeprecatedConfigurationProperty来提供。详细信息请参见更新后的附录( updated appendix )。

我们还改进了默认值的检测:如果一个属性是通过具有单个参数的方法调用进行初始化的,我们将该参数视为默认值(例如Charset.forName("UTF-8")将检测UTF-8作为默认值)。

一个新的spring-boot-configuration-metadata模块现在可供任何想在自己的工具和应用中使用配置元数据的工具开发人员使用;它提供了一个API来读取元数据并从中构建一个存储库。

Spring Boot CLI

现在,CLI将在依赖项解析期间使用Maven的settings.xml中配置的存储库。对于要使用的存储库,声明它的profile必须是active。

CLI现在还可以生成可执行的WAR文件。使用 $ spring war

Annotation processing

Apache HttpCore 4.4.5删除了一些注释(removed a handful of annotations)。如果您正在使用注解处理器,并且正在对使用删除的注解之一的类进行子类化,那么这是一个二进制不兼容的更改。例如,如果类使用了@Immutable,你会看到编译时注释处理失败,并出现[ERROR] diagnostic: error: cannot access org.apache.http.annotation.Immutable。

这个问题可以通过降级到HttpCore 4.4.4来避免,或者更好的是,通过结构化你的代码,这样有问题的类就不会受到编译时注释处理的影响。

Miscellaneous

Spring Boot 1.3中还包含了以下各种更新:

当使用Java 8,Jackson’s Java 8 模块将被自动注册。

TransactionTemplate bean现在作为TransactionAutoConfiguration的一部分包含在其中。

现在可以使用spring.mail.jndi-name属性通过JNDI获得MailServer bean。

现在可以通过server.display-name属性配置服务器名称(当使用嵌入式servlet容器时)。

Flyway迁移策略现在可以通过FlywayMigrationStrategy bean来配置。

添加了一个新的SpringBootVersion类(类似于核心框架中的SpringVersion)。

现在可以使用带有OutputCapture的hamcrest匹配器来验证测试产生的输出。

现在可以配置Spring Boot来使用Elasticsearch非本地节点。

如果设置了fail-on-write-error property属性,ApplicationPidFileWriter现在可以抛出异常(请参阅更新的javadoc)。

Maven插件现在包含一个useTestClasspath选项,用于spring-boot:run。

现在为DB2和Informix提供了额外的数据库健康查询。

属性绑定失败现在包括更好的异常消息。

@SpringBootApplication注释现在包括scanBasePackages和scanBasePackageClasses属性。

提供了新的AllNestedConditions和NoneNestedConditions(类似于现有的AnyNestedCondition)

当应用程序启动时,active profiles将被打印到输出日志中。

spring.main.banner-mode 属性可用于在CONSOLE, LOG 或者OFF输出之间切换。

远程开发工具现在可以在代理服务器后工作(see the spring.devtools.remote.proxy.* properties)。

Jackson’s parameter names module (providing Java 8 support) 现在将在类路径上自动配置。

Spring’s WebSocket 消息转换器现在将自动配置。

添加了一个新的DelegatingFilterProxyRegistrationBean类,允许通过DelegatingFilterProxy向嵌入的servlet容器注册过滤器。

Deprecations in Spring Boot 1.3.0

Application.showBanne 和 ApplicationBuilder.showBanner 方法已经被弃用,取而代之的是setBannerMode。22

@ConditionalOnMissingClass现在希望使用value属性而不是name来提供类名。

在Apache的EOL declaration for log4j 1.x.之后,Log4JLoggingSystem 现在已弃用。

ConfigurableEmbeddedServletContainer setJspServletClassName和setRegisterJspServlet方法已被setJspServlet取代。

EndpointMBean类(及其子类)现在希望向构造函数提供一个ObjectMapper。

DropwizardMetricWriter已经被DropwizardMetricService所取代。

受保护的SpringApplication.afterRefresh 方法接受String[]已被弃用,取而代之的是接受ApplicationArguments的版本。

VcapEnvironmentPostProcessor已被弃用,取而代之的是CloudFoundryVcapEnvironmentPostProcessor。

LoggingSystem initialize方法已经弃用,取而代之的是接受LoggingInitializationContext的版本。

ServerPortInfoApplicationContextInitializer已弃用,已将其移动到新包中

org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryBuilder 已经废弃了,移动到一个新的包。 org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder应该被使用替代。bean的老类型不在被自动配置。如果你的应用使用这个bean,它应该被更新使用org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder bean 替代。

你可能感兴趣的:(史上最全 SpringBoot 1.3.0.RELEASE 版本特性介绍(全文英译版))