Spring Boot?v1.4.0.RELEASE
Spring Boot 1.4.0 Release Notes
Upgrading from Spring Boot 1.3
Deprecations from Spring Boot 1.3
在Spring Boot 1.3中棄用的類、方法和屬性已經(jīng)在這個版本中刪除了。請確保在升級之前沒有調(diào)用已棄用的方法。
在?Apache EOL announcement?后已經(jīng)刪除了對Log4j 1 的支持
Renamed starters
以下啟動器已被重命名,舊的啟動器將在Spring Boot 1.5中刪除
spring-boot-starter-ws?→?spring-boot-starter-web-services
spring-boot-starter-redis?→?spring-boot-starter-data-redis
DataSourceProperties get methods
DataSourceProperties中的一些get…方法已被更改,以與其他@ConfigurationProperties類更加一致。如果你之前在你的代碼中直接調(diào)用了以下任何一個方法,你需要遷移到新的determine…()等號:
getDriverClassName()?→?determineDriverClassName()
getUrl()?→?determineUrl()
getUsername()?→?determineUsername()
getPassword()?→?determineUsername()
備注:get方法沒有被棄用,但它們的行為已經(jīng)改變,請確保在升級時手動檢查是否使用。
DataSource binding
Prior to Spring Boot 1.4, auto-configured datasources were bound to the?spring.datasource?namespace. In 1.4, we only bind the common settings to?spring.datasource?(see?DataSourceProperties) and we have defined newspecificnamespaces for the four connections pools we support (in that order):
在Spring Boot 1.4之前,自動配置的數(shù)據(jù)源被綁定到spring.datasource名稱空間。在1.4中,我們只將公共設(shè)置綁定到spring.datasource(參見DataSourceProperties),我們已經(jīng)為我們支持的四個連接池定義了新的明確的命名空間(按此順序):
spring.datasource.tomcat?for?org.apache.tomcat.jdbc.pool.DataSource
spring.datasource.hikari?for?com.zaxxer.hikari.HikariDataSource
spring.datasource.dbcp?for?org.apache.commons.dbcp.BasicDataSource
spring.datasource.dbcp2?for?org.apache.commons.dbcp2.BasicDataSource
如果使用正在使用的連接池實現(xiàn)的特定設(shè)置,則必須將該配置移動到相關(guān)的名稱空間。例如,如果您正在使用Tomcat的testOnBorrow標志,則必須將其從spring.datasource.test-on-borrow移走到spring.datasource.tomcat.test-on-borrow。
如果在IDE中使用配置幫助,現(xiàn)在可以看到每個連接池都有哪些設(shè)置可用,而不是在spring.datasource 名稱空間中將所有設(shè)置混合在一起。這將使您更容易地確定什么實現(xiàn)支持什么特性。
JTA settings binding
與數(shù)據(jù)源綁定類似,Atomikos和Bitronix的JTA提供程序特定配置屬性也被綁定到spring.jta。它們現(xiàn)在分別被綁定到spring.jta.atomikos.properties和spring.jta.bitronix.properties;這些條目的元數(shù)據(jù)也得到了極大的改進。
Hibernate 5
Hibernate 5.0現(xiàn)在被用作默認的JPA持久性提供程序。如果您從Spring Boot 1.3升級,那么您將從Hibernate 4.3升級到Hibernate 5.0。請參考Hibernate遷移文檔-Hibernate migration documentation?了解一般的升級說明。此外,你應(yīng)該知道以下幾點:
Naming Strategy
SpringNamingStrategy不再使用,因為Hibernate 5.1刪除了對舊的NamingStrategy接口的支持。一個新的SpringPhysicalNamingStrategy現(xiàn)在是自動配置的,它與Hibernate的默認ImplicitNamingStrategy一起使用。這應(yīng)該與Spring Boot 1.3默認值非常接近(如果不是完全相同的話),但是,在升級時應(yīng)該檢查數(shù)據(jù)庫模式是否正確。
如果您在升級之前已經(jīng)在使用Hibernate 5,那么您可能正在使用Hibernate 5的默認值。如果您想在升級后恢復(fù)它們,請在配置中設(shè)置此屬性:
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
Generator mappings
為了減少升級的痛苦,我們對于Hibernate設(shè)置了hibernate.id.new_generator_mappings=false。Hibernate團隊通常不推薦這種設(shè)置,所以如果您愿意處理生成器更改,您可能希望在application.properties文件中將spring.jpa.hibernate.use-new-id-generator-mappings設(shè)置為true。
Downgrading to Hibernate 4.3
如果你在升級到Hibernate 5.0時遇到了大問題,你可以在你的pom.xml中通過重?hibernate.version屬性來降級到舊的Hibernate版本:

或者在你的Gradle腳本重寫?hibernate.version 屬性:

備注:在Spring Boot 1.4之后,Hibernate 4.3將不受支持。如果你發(fā)現(xiàn)一個阻止你升級的bug-raise an issue,請?zhí)岢鲆粋€問題。
@EntityScan
@org.springframework.boot.orm.jpa.EntityScan注解已經(jīng)棄用,應(yīng)該用@org.springframework.boot.autoconfigure.domain.EntityScan替換或顯式配置。
例如,如果您有以下配置:

如果您使用的是自動配置LocalContainerEntityManagerFactoryBean, 切換到:

或者如果你正在定義你自己的LocalContainerEntityManagerFactoryBean,完全刪除@EntityScan注解,調(diào)用?LocalContainerEntityManagerFactoryBean.setPackagesToScan(…?)?或者使用EntityManagerFactoryBuilder packages(…)方法:

Test utilities and classes
Spring?Boot 1.4附帶了一個新的spring-boot-test?模塊,它包含了一個完全重組的org.springframework.boot.test包。升級Spring Boot 1.3應(yīng)用程序時,應(yīng)該從舊包中已棄用的類遷移到新結(jié)構(gòu)中的等價類。如果你正在使用Linux或OSX,你可以使用以下命令遷移代碼:
find . -type f -name '*.java' -exec sed -i '' \
-e s/org.springframework.boot.test.ConfigFileApplicationContextInitializer/org.springframework.boot.test.context.ConfigFileApplicationContextInitializer/g \
-e s/org.springframework.boot.test.EnvironmentTestUtils/org.springframework.boot.test.util.EnvironmentTestUtils/g \
-e s/org.springframework.boot.test.OutputCapture/org.springframework.boot.test.rule.OutputCapture/g \
-e s/org.springframework.boot.test.SpringApplicationContextLoader/org.springframework.boot.test.context.SpringApplicationContextLoader/g \
-e s/org.springframework.boot.test.SpringBootMockServletContext/org.springframework.boot.test.mock.web.SpringBootMockServletContext/g \
-e s/org.springframework.boot.test.TestRestTemplate/org.springframework.boot.test.web.client.TestRestTemplate/g \
{} \;
此外,Spring Boot 1.4試圖合理化和簡化Spring Boot測試可以運行的各種方法。您應(yīng)該遷移以下內(nèi)容以使用新的@SpringBootTest注解:
從 @SpringApplicationConfiguration(classes=MyConfig.class)?到 @SpringBootTest(classes=MyConfig.class)
從 @ContextConfiguration(classes=MyConfig.class, loader=SpringApplicationContextLoader.class)?到 @SpringBootTest(classes=MyConfig.class)
從 @IntegrationTest?到 @SpringBootTest(webEnvironment=WebEnvironment.NONE)
從 @IntegrationTest with @WebAppConfiguration?到 @SpringBootTest(webEnvironment=WebEnvironment.DEFINED_PORT)?(or?RANDOM_PORT)
從 @WebIntegrationTest?到 @SpringBootTest(webEnvironment=WebEnvironment.DEFINED_PORT)?(or?RANDOM_PORT)
提示:在遷移測試時,您可能還想用Spring 4.3中可讀性更強的@RunWith(SpringJUnit4ClassRunner.class)來替換任何@RunWith(SpringJUnit4ClassRunner.class)聲明。
For more details on the?@SpringBootTest?annotation refer to the?updated documentation.
TestRestTemplate
TestRestTemplate?類不再直接擴展RestTemplate(盡管它繼續(xù)提供相同的方法)。這允許將TestRestTemplate配置為bean,而不會意外地注入它。如果需要訪問實際的底層RestTemplate,請使用getRestTemplate()方法。
Maven spring-boot.version property
spring-boot.version?屬性已經(jīng)從 spring-boot-dependencies?pom.刪除。See?issue 5104?for details.
Integration Starter
spring-boot-starter-integration通過刪除四個典型Spring Integration?應(yīng)用程序不需要使用的模塊而得到了簡化。被刪除的四個模塊是:
spring-integration-file
spring-integration-http
spring-integration-ip
spring-integration-stream
如果你的應(yīng)用程序依賴于這四個模塊中的任何一個,你應(yīng)該給你的pom或build.gradle添加一個顯式的依賴項。
此外,spring-integration-java-dsl和spring-integration-jmx現(xiàn)在已經(jīng)添加到starter中。使用DSL是在應(yīng)用程序中配置Spring Integration的推薦方法。
Spring Batch Starter
spring-boot-starter-batch starter不再依賴于嵌入式數(shù)據(jù)庫。如果您依賴于這種安排,請?zhí)砑幽x擇的數(shù)據(jù)庫(驅(qū)動程序),例如:

如果您已經(jīng)配置了自己的hsqldb上的排除,那么現(xiàn)在可以刪除該排除。
Downgrading Tomcat
從Tomcat 8.5.4開始,?tomcat-juli模塊現(xiàn)在被打包為嵌入式Tomcat的一部分。大多數(shù)用戶不會注意到這個更改,但是,如果您手動降級到較老的Tomcat版本,那么您現(xiàn)在需要自己添加tomcat-juli模塊。有關(guān)更新的說明,請參閱如何使用文檔部分-how-to documentation section?。
Dispatch Options Request
默認spring.mvc.dispatch-options-request?屬性已經(jīng)從false改為true,以符合Spring框架的首選默認值。如果您不希望OPTIONS請求被分派到FrameworkServlet。你應(yīng)該顯式地設(shè)置?spring.mvc.dispatch-options-request?為false。
Forced character encoding
強制字符編碼現(xiàn)在只適用于請求(而不是響應(yīng))。如果您想強制對請求和響應(yīng)進行編碼,可以設(shè)置spring.http.encoding.force=true。
multipart屬性已經(jīng)從multipart.?命名空間移動到spring.http.multipart. 命名空間。
Server header
Server?HTTP響應(yīng)頭不再被設(shè)置,除非server.server-header屬性被設(shè)置。
@ConfigurationProperties default bean names
當通過@EnableConfigurationProperties(SomeBean.class)注冊@ConfigurationProperties bean時,我們使用<prefix>.CONFIGURATION_PROPERTIES形式生成一個bean名。從Spring Boot 1.4開始,我們已經(jīng)更改了該模式,以避免兩個bean使用相同前綴時發(fā)生名稱沖突。
新的常規(guī)名稱是<prefix>-<fqn>,其中<prefix>是@ConfigurationProperties注解中指定的環(huán)境鍵前綴,也是bean的完全限定名。如果注解不提供任何前綴,則只使用bean的完全限定名。
Jetty JNDI support
spring-boot-starter-jetty“Starter”不再包括org.eclipse.jetty:jetty-jndi。如果您使用具有JNDI的Jetty,您現(xiàn)在需要自己直接添加這個依賴項。
Guava caches
建議使用Guava緩存支持的開發(fā)人員遷移到Caffeine。
Remote Shell
CRaSH屬性已經(jīng)從shell.?命名空間移動到management.shell.?名稱空間。另外,身份驗證類型現(xiàn)在應(yīng)該通過management.shell.auth.type來定義。
Spring Session auto-configuration improvements
Spring Boot支持更多的Spring Session后端存儲:除了Redis, JDBC, MongoDB, Hazelcast和內(nèi)存并發(fā)哈希映射也支持。一個新的spring.session.store-type?store-type強制屬性引入了來選擇應(yīng)該使用的存儲 Spring Session。
Launch script identity
當啟動腳本確定應(yīng)用程序的默認標識時,現(xiàn)在將使用包含jar的目錄的規(guī)范名稱。以前,如果包含jar的目錄是一個符號鏈接,則使用符號鏈接的名稱。如果需要對應(yīng)用程序的標識進行更多的控制,則應(yīng)該使用APP_NAME環(huán)境變量。
MongoDB 3
Mongo的Java驅(qū)動程序的默認版本現(xiàn)在是3.2.2(從2.14.2),spring-boot-starter-data-mongodb已經(jīng)更新為使用新的首選mongodb-driver工件。
嵌入式MongoDB的自動配置也被更新為使用3.2.2作為默認版本。
Thymeleaf 3
默認情況下,Spring Boot使用的是Thymeleaf 2.1,但是現(xiàn)在它也兼容Thymeleaf 3,更多細節(jié)請查看更新后的文檔-updated documentation。
Executable jar layout
可執(zhí)行jar的布局已經(jīng)改變。如果您正在使用Spring Boot的Maven、Gradle或Ant支持來構(gòu)建應(yīng)用程序,那么此更改不會影響您。如果你自己構(gòu)建一個可執(zhí)行的存檔文件,請注意,應(yīng)用程序的依賴項現(xiàn)在打包在BOOT-INF/lib中,而不是lib中,應(yīng)用程序自己的類現(xiàn)在打包在BOOT-INF/classes中,而不是jar的根目錄中。
Jersey classpath scanning limitations
對可執(zhí)行jar布局的更改意味著Jersey的類路徑掃描的限制(?limitation in Jersey’s classpath scanning?)現(xiàn)在會影響可執(zhí)行jar文件和可執(zhí)行war文件。為了解決這個問題,您希望Jersey掃描的類應(yīng)該打包在一個jar中,并作為依賴項包含在BOOT-INF/lib中。Spring Boot啟動器應(yīng)該配置為在啟動時解包這些jar(configured to unpack those jars on start up?),以便Jersey可以掃描它們的內(nèi)容。
Integration tests with the?maven-failsafe-plugin
從Failsafe 2.19開始,target/classes不再在類路徑上,而是使用項目的構(gòu)建jar。由于可執(zhí)行jar布局的改變,插件將無法找到你的類。有兩種方法可以解決這個問題:
1. 降級到2.18.1,這樣你就可以使用target/classes了
2. 配置spring-boot-maven-plugin來使用aclassifier來實現(xiàn)重新打包的目標。這樣,原始的jar就可以被插件使用了。例如

備注:如果您正在使用Spring Boot的依賴項管理,那么沒有什么可做的,因為默認情況下您將使用2.18.1。
Tip Watch?SUREFIRE-1198?for updates on this issue.
HornetQ
對HornetQ的支持已被棄用。HornetQ的用戶應(yīng)該考慮遷移到Artemis。
@Transactional?default to cglib proxies
當啟動自動配置事務(wù)管理時,proxyTargetClass現(xiàn)在被設(shè)置為true(這意味著創(chuàng)建了cglib代理,而不是要求bean實現(xiàn)接口)。如果你想對其他沒有自動配置的方面的行為進行對齊,你需要現(xiàn)在顯式啟用該屬性:
@EnableCaching(proxyTargetClass=true)
備注:如果您碰巧在接口上使用了@Transactional,則必須顯式地將@EnableTransactionManagement添加到配置中。這將恢復(fù)以前的行為。
New and Noteworthy
Tip Check?the configuration changelog?for a complete overview of the changes in configuration.
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 theSpring Framework reference documentationfor details.
Spring Boot 1.4構(gòu)建于Spring Framework 4.3之上,并且需要Spring Framework 4.3。在Spring Framework 4.3中有許多出色的改進,包括新的Spring MVC @RequestMapping注釋。詳細信息請參考Spring Framework reference documentation。
注意,Spring framework 4.3中的測試框架需要JUnit 4.12。See?SPR-13275?for further details.
Third-party library upgrades
許多第三方庫已經(jīng)升級到最新版本。更新包括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。
幾個Maven插件也進行了升級。
Couchbase support
現(xiàn)在為Couchbase提供了完全的自動配置支持。通過添加spring-boot-starter-data-couchbase“Starter”并提供一些配置,你可以很容易地訪問Bucket和Cluster?bean:
spring.couchbase.bootstrap-hosts=my-host-1,192.168.1.123
spring.couchbase.bucket.name=my-bucket
spring.couchbase.bucket.password=secret
還可以使用Couchbase作為Spring Data?Repository?的后備存儲或CacheManager。Refer to the?updated documentation?for details。
Neo4J Support
Neo4J現(xiàn)在提供了自動配置支持。您可以連接到遠程服務(wù)器或運行嵌入式Neo4J服務(wù)器。你也可以使用Neo4J來支持Spring Data?Repository,例如:

Full details are provided in the?Neo4J section?of the reference documentation.
Redis Spring Data repositories
Redis現(xiàn)在可以用來支持Spring數(shù)據(jù)存儲庫。See the?Spring Data Redis?documentation for more details.
Narayana transaction manager support
自動配置支持現(xiàn)在包含在Narayana事務(wù)管理器中。如果您需要JTA支持,您可以選擇Narayana, Bitronix或Atomkos。See?the updated reference guide?for details。
Caffeine cache support
Caffeine?v2.2 (Java 8重寫了Guava的緩存支持)提供了自動配置?,F(xiàn)有的Guava?緩存用戶應(yīng)該考慮遷移到Caffeine?,因為Guava?緩存支持將在未來的版本中刪除。
Elasticsearch Jest support
如果Jest在類路徑上,Spring Boot會自動配置JestClient和專用的HealthIndicator。即使spring-data-elasticsearch不在類路徑上,也可以使用Elasticsearch。
Analysis of startup failures
Spring Boot現(xiàn)在將對常見的啟動失敗進行分析,并提供有用的診斷信息,而不僅僅是記錄異常及其堆棧跟蹤。例如,在Spring Boot的早期版本中,由于嵌入式servlet容器的端口正在使用而導(dǎo)致的啟動失敗如下所示:
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
在1.4版本中,它看起來是這樣的:
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.
如果您仍然想要查看底層原因的堆棧跟蹤,可以為org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter啟用調(diào)試日志記錄。
Image Banners
你現(xiàn)在可以使用圖像文件來渲染ASCII藝術(shù)橫幅。一個banner.gif, banner.jpg或banner.png文件到src/main/resources,使其自動轉(zhuǎn)換為ASCII。你可以使用banner.image.width和banner.image.height屬性來調(diào)整大小,或使用banner.image.invert顛倒顏色。
RestTemplate builder
可以使用新的RestTemplateBuilder輕松創(chuàng)建具有合理默認值的RestTemplate。默認情況下,構(gòu)建的RestTemplate將嘗試使用類路徑上可用的最合適的ClientHttpRequestFactory,并將知道要使用的MessageConverter實例(包括Jackson)。構(gòu)建器包括許多有用的方法,可用于快速配置RestTemplate。例如,要添加基本的認證支持,你可以使用:

自動配置的TestRestTemplate現(xiàn)在也使用RestTemplateBuilder。
JSON Components
現(xiàn)在為自定義Jackson JsonSerializer和 /or?JsonDeserializer?注冊提供了一個新的@JsonComponent注解。這是一種解耦JSON序列化邏輯的有用方法:

此外,Spring Boot現(xiàn)在還提供了JsonObjectSerializer和JsonObjectDeserializer基類,在序列化對象時提供了標準Jackson版本的有用替代方案。?See the?updated documentation?for details。
Convention based error pages
現(xiàn)在可以通過遵循基于約定的方法創(chuàng)建給定狀態(tài)代碼的自定義錯誤頁面。在/public/error中創(chuàng)建一個靜態(tài)HTML文件,或者使用狀態(tài)代碼作為文件名在/templates/error中添加一個模板。例如,要注冊一個自定義404文件,可以添加src/main/resource/public/error/404.html。See?the updated reference documentation?for details。
Unified?@EntityScan?annotation
org.springframework.boot.autoconfigure.domain.EntityScan現(xiàn)在可以用來指定用于JPA、Neo4J、MongoDB、Cassandra和Couchbase的包。因此,JPA特有的org.springframework.boot.orm.jpa.EntityScan現(xiàn)在已棄用。
ErrorPageRegistry
新的ErrorPageRegistry和ErrorPageRegistrar接口允許以一致的方式注冊錯誤頁面,而不管是否使用嵌入式servlet容器。ErrorPageFilter類已經(jīng)更新為ErrorPageRegistry,而不是一個虛假的ConfigurableEmbeddedServletContainer。
PrincipalExtractor
如果需要使用自定義邏輯提取OAuth2主體,現(xiàn)在可以使用PrincipalExtractor接口。
Test improvements
Spring Boot 1.4對測試支持進行了重大的修改?,F(xiàn)在在專用的spring-boot-test和spring-boot-test-autoconfigure jar中提供了測試類和實用程序(盡管大多數(shù)用戶將繼續(xù)通過spring-boot-starter-test“Starter”來獲取它們)。我們已經(jīng)向測試啟動器添加了AssertJ、JSONassert和JsonPath依賴項。
@SpringBootTest
在Spring Boot 1.3中,有多種編寫Spring Boot測試的方法。您可以使用@SpringApplicationConfiguration、@ContextConfiguration和SpringApplicationContextLoader、@IntegrationTest或@WebIntegrationTest。在SpringBoot 1.4中,一個@SpringBootTest注解可以替換所有這些。
結(jié)合使用@SpringBootTest和@RunWith(SpringRunner.class),并根據(jù)您想要編寫的測試類型設(shè)置webEnvironment屬性。
一個經(jīng)典的集成測試,使用一個模擬的servlet環(huán)境:

一個web集成測試,運行一個實時服務(wù)器在一個定義的端口上監(jiān)聽:

一個web集成測試,運行一個實時服務(wù)器在一個隨機端口上監(jiān)聽:

See the?updated reference documentation?for details.
Auto-detection of test configuration
現(xiàn)在可以為大多數(shù)測試自動檢測測試配置。如果您遵循Spring Boot為構(gòu)建代碼而推薦的約定,則在沒有定義顯式配置時將加載@SpringBootApplication類。如果您需要加載不同的@Configuration類,您可以將其作為嵌套的內(nèi)部類包含在您的測試中,或者使用@SpringBootTest的classes屬性。
See?Detecting test configuration?for details.
Mocking and spying beans
為了測試目的,通常希望用mock替換ApplicationContext中的單個bean。在Spring Boot 1.4中,這就像用@MockBean在測試中注解一個字段一樣簡單:

如果您想監(jiān)視現(xiàn)有bean而不是使用完整的mock,也可以使用@SpyBean。
See the?mocking section?of the reference documentation for more details.
Auto-configured tests
對測試來說,完全的應(yīng)用程序自動配置有時是多余的,您通常只想自動配置應(yīng)用程序的特定“部分”。Spring Boot 1.4引入了一些專門的測試注解,可以用來測試應(yīng)用程序的特定部分:
@JsonTest?- 測試JSON編組和解組。
@WebMvcTest?- 使用MockMVC測試Spring MVC @Controllers。
@RestClientTest?- 用于測試RestTemplate調(diào)用。
@DataJpaTest?- 用于測試Spring Data JPA元素
許多注解提供了特定于測試的附加自動配置。例如,如果你使用@WebMvcTest,你可以@Autowire一個完全配置的MockMvc實例。
See the?reference documentation?for details.
JSON AssertJ assertions
新的JacksonTester、GsonTester和BasicJsonTester類可以與AssertJ結(jié)合使用來測試JSON編組和解組。測試人員可以與@JsonTest注解一起使用,也可以直接在測試類中使用:

See the?JSON section?of the reference documentation or the Javadocs for details.
@RestClientTest
如果您想測試REST客戶端,可以使用@RestClientTest注解。默認情況下,它將自動配置Jackson和GSON支持,配置RestTemplateBuilder并添加對MockRestServiceServer的支持。
Auto-configuration for Spring REST Docs
結(jié)合上述對自動配置MockMvc的支持,Spring REST Docs的自動配置已經(jīng)被引入。可以使用新的@AutoConfigureRestDocs注解啟用REST Docs。這將導(dǎo)致MockMvc實例被自動配置為使用REST Docs,并且不再需要使用REST Docs的JUnit規(guī)則。詳情請參閱參考文檔的相關(guān)部分-relevant section。
Test utilities
spring-boot-starter-test 現(xiàn)在提供?AssertJ?assertions library.
測試實用程序從org.springframework.boot.test包中已經(jīng)轉(zhuǎn)移到spring-boot-test專用工件。
Actuator info endpoint improvements
現(xiàn)在,您可以使用InfoContributor接口注冊向/info執(zhí)行器端點公開信息的bean。提供開箱支持:
從?git-commit-id-plugin?Maven或gradle-git-properties?Gradle 插件中生成的全部或部分Git信息(設(shè)置?management.info.git.mode=full?以顯示全部細節(jié))
從Spring Boot Maven或Gradle插件生成的構(gòu)建信息。
自定義環(huán)境信息(任何屬性starting?info.*)
Details are documented in the?"Application information"?section of the reference docs.
MetricsFilter improvements
MetricsFilter現(xiàn)在可以以經(jīng)典的“merged”形式提交度量,或者按每個HTTP方法分組。使用endpoints.metrics.filter屬性以更改配置:
endpoints.metrics.filter.gauge-submissions=per-http-method
endpoints.metrics.filter.counter-submissions=per-http-method,merged
Spring Session JDBC Initializer
如果將Spring Session配置為使用JDBC存儲,那么模式將在啟動時自動創(chuàng)建。
Secured connection for Artemis/HornetQ
Spring Boot現(xiàn)在允許通過一個安全的Artemis/HornetQ代理進行連接。
Annotation processing
Apache HttpCore 4.4.5刪除了一些注解-?removed a handful of annotations。如果您正在使用注解處理器,并且正在對使用刪除的注解之一的類進行子類化,那么這是一個二進制不兼容的更改。例如,如果類使用了@Immutable,你會看到編譯時注解處理失敗,并出現(xiàn)[ERROR]診斷:ERROR: cannot access org.apache.http.annotation.Immutable。
這個問題可以通過降級到HttpCore 4.4.4來避免,或者更好的是,通過結(jié)構(gòu)化你的代碼,這樣有問題的類就不會受到編譯時注釋處理的影響。
Miscellaneous
server.jetty.acceptors和server.jetty.selectors屬性已經(jīng)添加了來配置Jetty接受器和選擇器的數(shù)量
server.max-http-header-size?和 server.max-http-post-size可以被用來約束 HTTP headers 和 HTTP POSTs最大數(shù)量。 設(shè)置工作在Tomcat, Jetty和Undertow
Tomcat的最小空閑線程數(shù)量現(xiàn)在可以使用server.tomcat.min-spare-threads配置
現(xiàn)在可以在application.yml文件使用配置文件否定。在?spring.profile values中使用熟悉的!?prefix
執(zhí)行器公開一個新的headdump端點,該端點返回一個GZip壓縮的hprof堆轉(zhuǎn)儲文件
Spring Mobile現(xiàn)在可以為所有支持的模板引擎自動配置
Spring Boot maven插件允許使用新的includeSystemScope屬性將系統(tǒng)范圍內(nèi)的工件打包
spring.mvc.log-resolved-exception啟用在HandlerExceptionResolver解決異常時自動記錄警告
spring.data.cassandra.schema-action用于自定義啟動時的模式操作
Spring Boot的fat jar格式現(xiàn)在應(yīng)該消耗更少的內(nèi)存
現(xiàn)在通過spring.http.encoding.mapping.<locale>=<charset> 屬性支持區(qū)域設(shè)置到字符集的映射。
默認情況下,使用spring.mvc.locale?的區(qū)域設(shè)置現(xiàn)在被請求的Accept-Language標頭覆蓋。要恢復(fù)1.3中頭文件被忽略的行為,設(shè)置spring.mvc.locale-resolve固定。
Deprecations in Spring Boot 1.4
對Velocity的支持已經(jīng)被棄用,因為它在Spring Framework 4.3中已經(jīng)被棄用了
UndertowEmbeddedServletContainer中的一些構(gòu)造函數(shù)已經(jīng)棄用(大多數(shù)使用應(yīng)該不受影響)。
@ConfigurationProperties注解的位置和合并屬性已經(jīng)棄用,而是支持直接配置環(huán)境。
保護的SpringApplication.printBanner方法不應(yīng)再用于打印自定義橫幅。使用Banner接口代替。
保護的InfoEndpoint.getAdditionalInfo方法已被棄用,取而代之的是InfoContributor接口。
org.springframework.boot.autoconfigure.test.ImportAutoConfiguration?已經(jīng)移動到 org.springframework.boot.autoconfigure.
?org.springframework.boot.test 包下的所有類已經(jīng)廢棄。 See the "upgrading" notes above for details.
PropertiesConfigurationFactory.setProperties(Properties)?被廢棄,取而代之的是使用PropertySources.
org.springframework.boot.context.embedded 包下的幾個類被廢棄 并且重新安置在org.springframework.boot.web.servlet.
org.springframework.boot.context.web包下的所有類被廢棄并且被重新安置
spring-boot-starter-ws?"Starter" 已經(jīng)重命名為spring-boot-starter-web-services.
spring-boot-starter-redis?"Starter" 已經(jīng)重命名為spring-boot-starter-data-redis.
spring-boot-starter-hornetq?starter 和 auto-configuration已經(jīng)被廢棄,取而代之的是spring-boot-starter-artemis
management.security.role已經(jīng)被廢棄,取而代之的是management.security.roles
@org.springframework.boot.orm.jpa.EntityScan?注解已經(jīng)被廢棄,取而代之的是@org.springframework.boot.autoconfigure.domain.EntityScan?或 顯示配置
TomcatEmbeddedServletContainerFactory.getValves()?已經(jīng)被廢棄,取而代之的是getContextValves().
org.springframework.boot.actuate.system.EmbeddedServerPortFileWriter?已經(jīng)被廢棄,取而代之的是org.springframework.boot.system.EmbeddedServerPortFileWriter
org.springframework.boot.actuate.system.ApplicationPidFileWriter已經(jīng)被廢棄,取而代之的是org.springframework.boot.system.ApplicationPidFileWriter
Property Renames
spring.jackson.serialization-inclusion?應(yīng)該被 spring.jackson.default-property-inclusion替代
spring.activemq.pooled?should 應(yīng)該被 spring.activemq.pool.enabled替代
spring.jpa.hibernate.naming-strategy應(yīng)該被spring.jpa.hibernate.naming.strategy替代
server.tomcat.max-http-header-size?應(yīng)該被 server.max-http-header-size替代