Spring Boot 1.4.0 Release Notes 更新日志-02

Spring Framework 4.3

Spring Boot 1.4 builds on and requires Spring Framework 4.3. There are a number of nice refinements in Spring Framework 4.3 including new Spring MVC @RequestMapping annotations. Refer to the Spring Framework reference documentation for details.

Note that the test framework in Spring Framework 4.3 requires JUnit 4.12. See SPR-13275 for further details.

Third-party library upgrades

A number of third party libraries have been upgraded to their latest version. Updates include Jetty 9.3, Tomcat 8.5, Jersey 2.23, Hibernate 5.0, Jackson 2.7, Solr 5.5, Spring Data Hopper, Spring Session 1.2, Hazelcast 3.6, Artemis 1.3, Ehcache 3.1, Elasticsearch 2.3, Spring REST Docs 1.1, Spring AMQP 1.6 & Spring Integration 4.3.

Several Maven plugins were also upgraded.

Couchbase support

Full auto-configuration support is now provided for Couchbase. You can easily access a Bucketand Cluster bean by adding the spring-boot-starter-data-couchbase "Starter" and providing a little configuration:

spring.couchbase.bootstrap-hosts=my-host-1,192.168.1.123 spring.couchbase.bucket.name=my-bucket spring.couchbase.bucket.password=secret

It’s also possible to use Couchbase as a backing store for a Spring Data Repository or as aCacheManager. Refer to the updated documentation for details.

Neo4J Support

Auto-configuration support is now provided for Neo4J. You can connect to a remote server or run an embedded Neo4J server. You can also use Neo4J to back a Spring Data Repository, for example:

public interface CityRepository extends GraphRepository {    Page findAll(Pageable pageable);    City findByNameAndCountry(String name, String country); }

Full details are provided in the Neo4J section of the reference documentation.

Redis Spring Data repositories

Redis can now be used to back Spring Data repositories. See the Spring Data Redis documentation for more details.

Narayana transaction manager support

Auto-configuration support is now included for the Narayana transaction manager. You can choose between Narayana, Bitronix or Atomkos if you need JTA support. See the updated reference guidefor details.

Caffeine cache support

Auto-configuration is provided for Caffeine v2.2 (a Java 8 rewrite of Guava’s caching support). Existing Guava cache users should consider migrating to Caffeine as Guava cache support will be dropped in a future release.

Elasticsearch Jest support

Spring Boot auto-configures a JestClient and a dedicated HealthIndicator if Jest is on the classpath. This allows you to use Elasticsearch even when spring-data-elasticsearch isn’t on the classpath.

Analysis of startup failures

Spring Boot will now perform analysis of common startup failures and provide useful diagnostic information rather than simply logging an exception and its stack trace. For example, a startup failure due to the embedded servlet container’s port being in use looked like this in earlier versions of Spring Boot:

2016-02-16 17:46:14.334 ERROR 24753 --- [           main] o.s.boot.SpringApplication               : Application startup failed java.lang.RuntimeException: java.net.BindException: Address already in use     at io.undertow.Undertow.start(Undertow.java:181) ~[undertow-core-1.3.14.Final.jar:1.3.14.Final]     at org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainer.start(UndertowEmbeddedServletContainer.java:121) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:293) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:141) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]     at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]     at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]     at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]     at sample.undertow.SampleUndertowApplication.main(SampleUndertowApplication.java:26) [classes/:na] Caused by: java.net.BindException: Address already in use     at sun.nio.ch.Net.bind0(Native Method) ~[na:1.8.0_60]     at sun.nio.ch.Net.bind(Net.java:433) ~[na:1.8.0_60]     at sun.nio.ch.Net.bind(Net.java:425) ~[na:1.8.0_60]     at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) ~[na:1.8.0_60]     at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74) ~[na:1.8.0_60]     at org.xnio.nio.NioXnioWorker.createTcpConnectionServer(NioXnioWorker.java:190) ~[xnio-nio-3.3.4.Final.jar:3.3.4.Final]     at org.xnio.XnioWorker.createStreamConnectionServer(XnioWorker.java:243) ~[xnio-api-3.3.4.Final.jar:3.3.4.Final]     at io.undertow.Undertow.start(Undertow.java:137) ~[undertow-core-1.3.14.Final.jar:1.3.14.Final]     ... 11 common frames omitted

In 1.4, it will look like this:

2016-02-16 17:44:49.179 ERROR 24745 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : *************************** APPLICATION FAILED TO START *************************** Description: Embedded servlet container failed to start. Port 8080 was already in use. Action: Identify and stop the process that‘s listening on port 8080 or configure this application to listen on another port.

If you still want to see the stacktrace of the underlying cause, enable debug logging fororg.springframework.boot.diagnostics.LoggingFailureAnalysisReporter.

Image Banners

You can now use image files to render ASCII art banners. Drop a banner.gifbanner.jpg orbanner.png file into src/main/resources to have it automatically converted to ASCII. You can use the banner.image.width and banner.image.height properties to tweak the size, or usebanner.image.invert to invert the colors.

RestTemplate builder

A new RestTemplateBuilder can be used to easily create a RestTemplate with sensible defaults. By default, the built RestTemplate will attempt to use the most suitable ClientHttpRequestFactoryavailable on the classpath and will be aware of the MessageConverter instances to use (including Jackson). The builder includes a number of useful methods that can be used to quickly configure aRestTemplate. For example, to add BASIC auth support you can use:

@Beanpublic RestTemplate restTemplate(RestTemplateBuilder builder) {    return builder.basicAuthorization("user", "secret").build(); }

The auto-configured TestRestTemplate now uses the RestTemplateBuilder as well.

JSON Components

A new @JsonComponent annotation is now provided for custom Jackson JsonSerializer and/orJsonDeserializer registration. This can be a useful way to decouple JSON serialization logic:

@JsonComponentpublic class Example {    public static class Serializer extends JsonSerializer {        // ...     }    public static class Deserializer extends JsonDeserializer {        // ...     } }

Additionally, Spring Boot also now provides JsonObjectSerializer and JsonObjectDeserializerbase classes which provide useful alternatives to the standard Jackson versions when serializing objects. See the updated documentation for details.

Convention based error pages

Custom error pages for a given status code can now be created by following a convention based approach. Create a static HTML file in /public/error or add a template to /templates/error using the status code as the filename. For example, to register a custom 404 file you could addsrc/main/resource/public/error/404.html. See the updated reference documentation for details.

Unified @EntityScan annotation

org.springframework.boot.autoconfigure.domain.EntityScan can now be used to specify the packages to use for JPA, Neo4J, MongoDB, Cassandra and Couchbase. As a result, the JPA-specificorg.springframework.boot.orm.jpa.EntityScan is now deprecated.

ErrorPageRegistry

New ErrorPageRegistry and ErrorPageRegistrar interfaces allow error pages to be registered in a consistent way regardless of the use of an embedded servlet container. The ErrorPageFilter class has been updated to that it is now a ErrorPageRegistry and not a fakeConfigurableEmbeddedServletContainer.

PrincipalExtractor

The PrincipalExtractor interface can now be used if you need to extract the OAuth2 Principalusing custom logic.

Test improvements

Spring Boot 1.4 includes a major overhaul of testing support. Test classes and utilities are now provided in dedicated spring-boot-test and spring-boot-test-autoconfigure jars (although most users will continue to pick them up via the spring-boot-starter-test "Starter"). We’ve added AssertJ, JSONassert and JsonPath dependencies to the test starter.

@SpringBootTest

With Spring Boot 1.3 there were multiple ways of writing a Spring Boot test. You could use@SpringApplicationConfiguration@ContextConfiguration with theSpringApplicationContextLoader@IntegrationTest or @WebIntegrationTest. With Spring Boot 1.4, a single @SpringBootTest annotation replaces all of those.

Use @SpringBootTest in combination with @RunWith(SpringRunner.class) and set thewebEnvironment attribute depending on the type of test you want to write.

A classic integration test, with a mocked servlet environment:

@RunWith(SpringRunner.class) @SpringBootTestpublic class MyTest {    // ...}

A web integration test, running a live server listening on a defined port:

@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment=WebEnvionment.DEFINED_PORT)public class MyTest {    // ...}

A web integration test, running a live server listening on a random port:

@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment=WebEnvionment.RANDOM_PORT)public class MyTest { @LocalServerPort private int actualPort;	// ...}

See the updated reference documentation for details.

Auto-detection of test configuration

Test configuration can now be automatically detected for most tests. If you follow the Spring Boot recommended conventions for structuring your code the @SpringBootApplication class will be loaded when no explicit configuration is defined. If you need to load a different @Configurationclass you can either include it as a nested inner-class in your test, or use the classes attribute of@SpringBootTest.

See Detecting test configuration for details.

Mocking and spying beans

It’s quite common to want to replace a single bean in your ApplicationContext with a mock for testing purposes. With Spring Boot 1.4 this now as easy as annotating a field in your test with@MockBean:

@RunWith(SpringRunner.class) @SpringBootTestpublic class MyTest {    @MockBean     private RemoteService remoteService;    @Autowired     private Reverser reverser;    @Test     public void exampleTest() {        // RemoteService has been injected into the reverser bean         given(this.remoteService.someCall()).willReturn("mock");        String reverse = reverser.reverseSomeCall();         assertThat(reverse).isEqualTo("kcom");     } }

You can also use @SpyBean if you want to spy on an existing bean rather than using a full mock.

See the mocking section of the reference documentation for more details.

Auto-configured tests

Full application auto-configuration is sometime overkill for tests, you often only want to auto-configure a specific "slice" of your application. Spring Boot 1.4 introduces a number of specialized test annotations that can be used for testing specific parts of your application:

  • @JsonTest - For testing JSON marshalling and unmarshalling.
  • @WebMvcTest - For testing Spring MVC @Controllers using MockMVC.
  • @RestClientTest - For testing RestTemplate calls.
  • @DataJpaTest - For testing Spring Data JPA elements

Many of the annotations provide additional auto-configuration that’s specific to testing. For example, if you use @WebMvcTest you can @Autowire a fully configured MockMvc instance.

See the reference documentation for details.

JSON AssertJ assertions

New JacksonTesterGsonTester and BasicJsonTester classes can be used in combination with AssertJ to test JSON marshalling and unmarshalling. Testers can be used with the @JsonTestannotation or directly on a test class:

@RunWith(SpringRunner.class) @JsonTestpublic class MyJsonTests {    private JacksonTester json;    @Test     public void testSerialize() throws Exception {        VehicleDetails details = new VehicleDetails("Honda", "Civic");         assertThat(this.json.write(details)).isEqualToJson("expected.json");         assertThat(this.json.write(details)).hasJsonPathStringValue("@.make");     } }

See the JSON section of the reference documentation or the Javadocs for details.

@RestClientTest

The @RestClientTest annotation can be used if you want to test REST clients. By default it will auto-configure Jackson and GSON support, configure a RestTemplateBuilder and add support forMockRestServiceServer.

Auto-configuration for Spring REST Docs

Combined with the support for auto-configuring MockMvc described above, auto-configuration for Spring REST Docs has been introduced. REST Docs can be enabled using the new@AutoConfigureRestDocs annotation. This will result in the MockMvc instance being automatically configured to use REST Docs and also removes the need to use REST Docs‘ JUnit rule. Please see the relevant section of the reference documentation for further details.

Test utilities

spring-boot-starter-test now brings the AssertJ assertions library.

Test utilities from the org.springframework.boot.test package have been moved to a spring-boot-test dedicated artifact.

Actuator info endpoint improvements

You can now use the InfoContributor interface to register beans that expose information to the/info actuator endpoint. Out of the box support is provided for:

  • Full or partial Git information generated from the git-commit-id-plugin Maven or gradle-git-properties Gradle plugin (set management.info.git.mode=full to expose full details)
  • Build information generated from the Spring Boot Maven or Gradle plugin.
  • Custom information from the Environment (any property starting info.*)

Details are documented in the "Application information" section of the reference docs.

MetricsFilter improvements

The MetricsFilter can now submit metrics in both the classic "merged" form, or grouped per HTTP method. Use endpoints.metrics.filter properties to change the configuration:

endpoints.metrics.filter.gauge-submissions=grouped endpoints.metrics.filter.counter-submissions=grouped,merged

Spring Session JDBC Initializer

If Spring Session is configured to use the JDBC store, the schema is now created automatically on startup.

Secured connection for Artemis/HornetQ

Spring Boot now allows to connect against a secured Artemis/HornetQ broker.

Miscellaneous

  • server.jetty.acceptors and server.jetty.selectors properties have been added to configure the number of Jetty acceptors and selectors.
  • server.max-http-header-size and server.max-http-post-size can be used to constrain maximum sizes for HTTP headers and HTTP POSTs. Settings work on Tomcat, Jetty and Undertow.
  • The minimum number of spare threads for Tomcat can now be configured usingserver.tomcat.min-spare-threads
  • Profile negation in now supported in application.yml files. Use the familiar ! prefix inspring.profiles values
  • The actuator exposes a new headdump endpoint that returns a GZip compressed hprof heap dump file
  • Spring Mobile is now auto-configured for all supported template engines
  • The Spring Boot maven plugin allows to bundle system scoped artifacts using the newincludeSystemScope attribute
  • spring.mvc.log-resolved-exception enables the automatic logging of a warning when an exception is resolved by a HandlerExceptionResolver
  • spring.data.cassandra.schema-action you be used to customize the schema action to take on startup
  • Spring Boot’s fat jar format should now consume much less memory
  • Locale to Charset mapping is now supported via the spring.http.encoding.mapping. property

Spring Data "Ingalls" release train support

Spring Boot 1.4 GA ships with the Spring Data "Hopper" release out of the box. Users that would like to try the "Ingalls" release train (available in milestone one at the time of writing) can do so by just setting the spring-data-releasetrain.version property to Ingalls-M1 and declaring the Spring milestone repository.

Depending on what modules of Spring Data you use, you might have to upgrade a couple of transitive dependencies, too:

  • Spring Data REST users will have to upgrade to Spring HATEOAS 0.21 (set spring-hateoas.version to 0.21.0.RELEASE)
  • Spring Data Redis users using Jedis as driver will have to upgrade to 2.9 (set jedis.version to2.9.0)

Deprecations in Spring Boot 1.4

  • Velocity support has been deprecated since support has been deprecated as of Spring Framework 4.3.
  • Some constructors in UndertowEmbeddedServletContainer have been deprecated (most uses should be unaffected).
  • The locations and merge attributes of the @ConfigurationProperties annotation have been deprecated in favor of directly configuring the Environment.
  • The protected SpringApplication.printBanner method should no longer be used to print a custom banner. Use the Banner interface instead.
  • The protected InfoEndpoint.getAdditionalInfo method has been deprecated in favor of theInfoContributor interface.
  • org.springframework.boot.autoconfigure.test.ImportAutoConfiguration has been moved toorg.springframework.boot.autoconfigure.
  • All classes in the org.springframework.boot.test package have been deprecated. See the "upgrading" notes above for details.
  • PropertiesConfigurationFactory.setProperties(Properties) is deprecated in favor of usingPropertySources.
  • Several classes in the org.springframework.boot.context.embedded package have been deprecated and relocated to org.springframework.boot.web.servlet.
  • All classes in the org.springframework.boot.context.web package have been deprecated and relocated.
  • The spring-boot-starter-ws "Starter" has been renamed to spring-boot-starter-web-services.
  • The spring-boot-starter-redis "Starter" has been renamed to spring-boot-starter-data-redis.
  • The spring-boot-starter-hornetq starter and auto-configuration has been deprecated in favour of using spring-boot-starter-artemis
  • management.security.role has been deprecated in favour of management.security.roles
  • The @org.springframework.boot.orm.jpa.EntityScan annotation has been deprecated in favor of @org.springframework.boot.autoconfigure.domain.EntityScan or explicit configuration.
  • TomcatEmbeddedServletContainerFactory.getValves() has been deprecated in favor ofgetContextValves().
  • org.springframework.boot.actuate.system.EmbeddedServerPortFileWriter has been deprecated in favor of org.springframework.boot.system.EmbeddedServerPortFileWriter
  • org.springframework.boot.actuate.system.ApplicationPidFileWriter has been deprecated in favor of org.springframework.boot.system.ApplicationPidFileWriter

Property Renames

  • spring.jackson.serialization-inclusion should be replaced with spring.jackson.default-property-inclusion.
  • spring.activemq.pooled should be replaced with spring.activemq.pool.enabled.
  • spring.jpa.hibernate.naming-strategy should be replaced withspring.jpa.hibernate.naming.strategy.
  • server.tomcat.max-http-header-size should be replaced with server.max-http-header-size.

博文参考:http://www.roncoo.com/article/index

时间: 2024-08-06 11:56:12

Spring Boot 1.4.0 Release Notes 更新日志-02的相关文章

Spring Boot 2.1.0 已发布,7 个重大更新你需要了解

Spring Boot 2.1.0 在 10 月底就发布了,我们来看下 Spring Boot 2.1.0 都更新了什么,每一个 Java 技术人都值得关注. 栈长其实早就看到了更新了,现在才有时间来更新下. 1.第三方类库升级 Hibernate 5.3 Micrometer 1.1 Reactor Californium Spring Data Lovelace Spring Framework 5.1 Tomcat 9 Undertow 2 主要就更新了这些类库,其实远不止这些. 2.性能

【重磅】Spring Boot 2.1.0 权威发布

如果这两天登录 https://start.spring.io/ 就会发现,Spring Boot 默认版本已经升到了 2.1.0.这是因为 Spring Boot 刚刚发布了 2.1.0 版本,我们来看下 Spring Boot 2 发布以来第一个子版本都发布了哪些内容? 2.1 中的新特性 将spring-boot-starter-oauth2-oidc-client重命名为spring-boot-starter-oauth2-client命名更简洁 添加 OAuth2 资源服务 start

Spring Boot 2.2.2.RELEASE 版本中文参考文档

写在前面 在我初次接触MongoDB的时候,是为了做一个监控系统和日志分析系统.当时在用Java操作MongoDB数据里的数据的时候,都是在网上查找Demo示例然后完成的功能,相信大家也同样的体会,网上大都是这种一个入门的小Demo,很少有深入讲解的.功能调通后,自己琢磨效率方面的问题,便开始自己的瞎尝试之路,然后在产品启动阶段初始化多个MongoClient对象,搞了一个类似于连接池一类的池子,完成之后打心眼里觉得自己真是个小机灵鬼. 大概过了一年,为了系统地学习MongoDB的一些高级特性,

Spring Boot 2.2.2.RELEASE 版本中文参考文档【3.2 - 3.10】

Spring Boot 2.2.2.RELEASE版本中文文档持续更新中~如有需要获取参考文档文件,关注公众号JavaSo,回复“参考文档”即可. 3.2 结构化代码 Spring Boot不需要任何特定的代码布局即可工作.但是,有一些最佳做法会有所帮助. 3.2.1 使用“default”包 当一个类不包含引入包声明时,将其视为在默认包中.通常不建议使用默认包,应避免这种情况.对于使用@ ComponentScan,@ ConfigurationPropertiesScan,@ EntityS

Git for Windows v2.11.0 Release Notes

homepage faq contribute bugs questions Git for Windows v2.11.0 Release Notes Latest update: December 1st 2016 Introduction These release notes describe issues specific to the Git for Windows release. The release notes covering the history of the core

001-Spring Cloud Edgware.SR3 升级最新 Finchley.SR1,spring boot 1.5.9.RELEASE 升级2.0.4.RELEASE注意问题点

一.前提 升级前 => 升级后 Spring Boot 1.5.x => Spring Boot 2.0.4.RELEASE Spring Cloud Edgware SR3 => Spring Cloud Finchley.SR1 1.1.Eureka Server ureka Server 依赖更新 升级前: <dependency> <groupId>org.springframework.cloud</groupId> <artifact

Spring Boot 2.2.0,性能提升+支持Java13

随着 Spring Framework 5.2.0 成功发布之后,Spring Boot 2.2 也紧跟其后,发布了第一个版本:2.2.0.下面就来一起来看看这个版本都更新了些什么值得我们关注的内容. 组件版本更新 这些Spring框架组件更新了依赖版本: Spring AMQP 2.2 Spring Batch 4.2 Spring Data Moore Spring Framework 5.2 Spring HATEOAS 1.0 Spring Integration 5.2 Spring

MongoDB 3.0 Release Notes

MongoDB 3.0支持WiredTiger存储引擎,提供可插拔存储引擎API,新增SCRAM-SHA-1认证机制,改进explain功能. 可插拔存储引擎API 允许第三方为MongoDB开发存储引擎 WiredTiger存储引擎 首次引入WiredTiger存储引擎,目前支持两种存储引擎: MMAPv1,3.0版本之前的存储引擎,也是3.0默认的存储引擎 WiredTiger,仅可用于MongoDB 3.0 64位版本 用法 WiredTiger支持MonoDB的所有特征,复制集和分片集群

Spring Boot OAuth 2.0 客户端

在上一篇<OAuth 2.0 授权码请求>中我们已经可以获取到access_token了,本节将使用客户端来访问远程资源 配置资源服务器 授权服务器负责生成并发放访问令牌(access_token),客户端在访问受保护的资源时会带上访问令牌,资源服务器需要解析并验证客户端带的这个访问令牌. 如果你的资源服务器同时也是一个授权服务器(资源服务器和授权服务器在一起),那么资源服务器就不需要考虑令牌解析的事情了,否则这一步是不可或缺的. To use the access token you nee