Spring Boot 1.4.0 Release Notes
Upgrading from Spring Boot 1.3
Deprecations from Spring Boot 1.3
Classes, methods and properties that were deprecated in Spring Boot 1.3 have been removed in this release. Please ensure that you aren’t calling deprecated methods before upgrading.
Log4j 1 support has been removed following Apache EOL announcement.
Renamed starters
The following starters have been renamed, the old ones will be removed in Spring Boot 2.0
-
spring-boot-starter-ws
→spring-boot-starter-web-services
-
spring-boot-starter-redis
→spring-boot-starter-data-redis
DataSourceProperties get methods
Some get…
methods from DataSourceProperties
have been changed to be more consistent with other @ConfigurationProperties
classes. If you previously directly called any of the following methods in your code, you will need to migrate to the new determine…()
equivalents:
-
getDriverClassName()
→determineDriverClassName()
-
getUrl()
→determineUrl()
-
getUsername()
→determineUsername()
-
getPassword()
→determineUsername()
Note | The get methods are not deprecated but their behavior has changed, make sure that you manually check for usage when upgrading. |
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
(seeDataSourceProperties
) and we have defined new specific namespaces for the four connections pools we support (in that order):
-
spring.datasource.tomcat
fororg.apache.tomcat.jdbc.pool.DataSource
-
spring.datasource.hikari
forcom.zaxxer.hikari.HikariDataSource
-
spring.datasource.dbcp
fororg.apache.commons.dbcp.BasicDataSource
-
spring.datasource.dbcp2
fororg.apache.commons.dbcp2.BasicDataSource
If you were using specific settings of the connection pool implementation that you are using, you will have to move that configuration to the relevant namespace. For instance, if you were using Tomcat’s testOnBorrow
flag, you’ll have to move it from spring.datasource.test-on-borrow
tospring.datasource.tomcat.test-on-borrow
.
If you are using configuration assistance in your IDE, you can now see which settings are available per connection pools rather than having all of them mixed in the spring.datasource
namespace. This should make your life much easier figuring out what implementation supports what features.
JTA settings binding
Similarly to DataSource binding
, JTA provider-specific configuration properties for Atomikos and Bitronix were bound to spring.jta
. They are now bound to spring.jta.atomikos.properties
andspring.jta.bitronix.properties
respectively; the meta-data for these entries has been greatly improved as well.
Hibernate 5
Hibernate 5.0 is now used as the default JPA persistence provider. If you are upgrading from Spring Boot 1.3 you will be moving from Hibernate 4.3 to Hibernate 5.0. Please refer to Hibernate migration documentation for general upgrade instructions. In addition you should be aware of the following:
Naming Strategy
SpringNamingStrategy
is no longer used as Hibernate 5.1 has removed support for the oldNamingStrategy
interface. A new SpringPhysicalNamingStrategy
is now auto-configured which is used in combination with Hibernate’s default ImplicitNamingStrategy
. This should be very close to (if not identical) to Spring Boot 1.3 defaults, however, you should check your Database schema is correct when upgrading.
If you were already using Hibernate 5 before upgrading, you may be using Hibernate’s 5 default. If you want to restore them after the upgrade, set this property in your configuration:
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
Generator mappings
In order to minimize upgrade pain, we set hibernate.id.new_generator_mappings
to false
for Hibernate 5. The Hibernate team generally don’t recommend this setting, so if you’re happy to deal with generator changes, you might want to set spring.jpa.hibernate.use-new-id-generator-mappings
to true
in your application.properties
file.
Downgrading to Hibernate 4.3
If you have major problems upgrading to Hibernate 5.0 you can downgrade to the older Hibernate version by overriding the hibernate.version
property in your pom.xml
:
4.3.11.Final
Or overriding the hibernate.version
property in your Gradle script:
ext['hibernate.version'] = '4.3.11.Final'
Note | Hibernate 4.3 will not be supported past Spring Boot 1.4. Please raise an issue if you find a bug that prevents you from upgrading. |
@EntityScan
The @org.springframework.boot.orm.jpa.EntityScan
annotation has been deprecated and should be replaced with @org.springframework.boot.autoconfigure.domain.EntityScan
or explicit configuration.
For example, if you have following configuration:
import org.springframework.boot.autoconfigure.SpringApplication; import org.springframework.boot.orm.jpa.EntityScan; @SpringBootApplication @EntityScan(basePackageClasses=Customer.class) public class MyApplication { // .... }
If you’re using an auto-configured LocalContainerEntityManagerFactoryBean
, switch to:
import org.springframework.boot.autoconfigure.SpringApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; @SpringBootApplication @EntityScan(basePackageClasses=Customer.class) public class MyApplication { // .... }
Or if you’re defining your own LocalContainerEntityManagerFactoryBean
drop the @EntityScan
annotation entirely and either call LocalContainerEntityManagerFactoryBean.setPackagesToScan(…)
or make use of the EntityManagerFactoryBuilder
packages(…)
method:
@Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory( EntityManagerFactoryBuilder builder) { return builder .dataSource(...) .properties(...) .packages(Customer.class) .build(); }
Test utilities and classes
Spring Boot 1.4 ships with a new spring-boot-test
module that contains a completely reorganized org.springframework.boot.test
package. When upgrading a Spring Boot 1.3 application you should migrate from the deprecated classes in the old package to the equivalent class in the new structure. If you’re using Linux or OSX, you can use the following command to migrate code:
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 \ {} \;
Additionally, Spring Boot 1.4 attempts to rationalize and simplify the various ways that a Spring Boot test can be run. You should migrate the following to use the new @SpringBootTest
annotation:
-
From
@SpringApplicationConfiguration(classes=MyConfig.class)
to@SpringBootTest(classes=MyConfig.class)
-
From
@ContextConfiguration(classes=MyConfig.class, loader=SpringApplicationContextLoader.class)
to@SpringBootTest(classes=MyConfig.class)
-
From
@ContextConfiguration(classes=MyConfig.class, loader=SpringApplicationContextLoader.class)
to@SpringBootTest(classes=MyConfig.class)
-
From
@IntegrationTest
to@SpringBootTest(webEnvironment=WebEnvironment.NONE)
-
From
@IntegrationTest with @WebAppConfiguration
to@SpringBootTest(webEnvironment=WebEnvironment.DEFINED_PORT)
(orRANDOM_PORT
) -
From
@WebIntegrationTest
to@SpringBootTest(webEnvironment=WebEnvironment.DEFINED_PORT)
(orRANDOM_PORT
)
Tip | Whilst migrating tests you may also want to replace any@RunWith(SpringJUnit4ClassRunner.class) declarations with Spring 4.3’s more readable@RunWith(SpringRunner.class) . |
For more details on the @SpringBootTest
annotation refer to the updated documentation.
TestRestTemplate
The TestRestTemplate
class no longer directly extends RestTemplate
(although it continues to offer the same methods). This allows TestRestTemplate
to be configured as a bean without it being accidentally injected. If you need access to the actual underlying RestTemplate
use thegetRestTemplate()
method.
Maven spring-boot.version property
The spring-boot.version
property has been removed from the spring-boot-dependencies
pom. See issue 5104 for details.
Integration Starter
spring-boot-starter-integration
has been streamlined by removing four modules that are not necessarily used by a typical Spring Integration application. The four modules removed were:
-
spring-integration-file
-
spring-integration-http
-
spring-integration-ip
-
spring-integration-stream
If your application relies on any of these four modules, you should add an explicit dependency to your pom or build.gradle.
Additionally, spring-integration-java-dsl
and spring-integration-jmx
have now been added to the starter. Using the DSL is the recommended way to configure Spring Integration in your application.
Spring Batch Starter
The spring-boot-starter-batch
starter no longer depends on an embedded database. If you were relying on this arrangement, please add a database (driver) of your choice, e.g.
org.springframework.boot spring-boot-starter-batch org.hsqldb hsqldb runtime
If you had an exclusion on hsqldb
as you were already configuring your own, you can now remove the exclusion.
Downgrading Tomcat
As of Tomcat 8.5.4 the tomcat-juli
module is now packaged as part of tomcat-embedded
. Most users won’t notice this change, however, if you manually downgrade to an older version of Tomcat you’ll now need to add the tomcat-juli
module yourself. See the how-to documentation sectionfor updated instructions.
Dispatch Options Request
The default spring.mvc.dispatch-options-request
property has changed from false
to true
to align with Spring Framework’s preferred default. If you don’t want OPTIONS
requests to be dispatched to FrameworkServlet.doService
you should explicitly set spring.mvc.dispatch-options-request
to false
.
Forced character encoding
Forced character encoding now only applies to requests (and not responses). If you want to force encoding for both requests and responses set spring.http.encoding.force
to true
.
Multipart support
The multipart properties have moved from the multipart.
namespace to thespring.http.multipart.
namespace.
Server header
The Server
HTTP response header is no longer set unless the server.server-header
property is set.
@ConfigurationProperties default bean names
When a @ConfigurationProperties
bean is registered via@EnableConfigurationProperties(SomeBean.class)
, we used to generate a bean name of the form. As of Spring Boot 1.4, we have changed that pattern to avoid name clashes if two beans use the same prefix.
The new conventional name is , where
is the environment key prefix specified in the
@ConfigurationProperties
annotation and
Jetty JNDI support
The spring-boot-starter-jetty
"Starter" no longer includes org.eclipse.jetty:jetty-jndi
. If you are using Jetty with JNDI you will now need to directly add this dependency yourself.
Guava caches
Developers using Guava cache support are advised to migrate to Caffeine.
Remote Shell
The CRaSH
properties have moved from the shell.
namespace to the management.shell.
namespace. Also, the authentication type should now be defined via management.shell.auth.type
.
Spring Session auto-configuration improvements
Spring Boot supports more backend stores for Spring Session: alongside Redis, JDBC, MongoDB, Hazelcast and in memory concurrent hash maps are also supported. A new spring.session.store-type
mandatory property has been introduced to select the store Spring Session should be using.
Launch script identity
When the launch script is determining the application’s default identity, the canonical name of the directory containing the jar will now be used. Previously, if the directory containing the jar was a symlink, the name of the symlink was used. If you require more control over the application’s identity, the APP_NAME
environment variable should be used.
MongoDB 3
The default version of Mongo’s Java Driver is now 3.2.2 (from 2.14.2) and spring-boot-starter-data-mongodb
has been updated to use the new, preferred mongodb-driver
artifact.
The auto-configuration for Embedded MongoDB has also been updated to use 3.2.2 as its default version.
Thymeleaf 3
By default, Spring Boot uses Thymeleaf 2.1 but it is now compatible with Thymeleaf 3 as well, check the updated documentation for more details.
Executable jar layout
The layout of executable jars has changed. If you are using Spring Boot’s Maven, Gradle, or Ant support to build your application this change will not affect you. If you are building an executable archive yourself, please be aware that an application’s dependencies are now packaged in BOOT-INF/lib
rather than lib
, and an application’s own classes are now packaged in BOOT-INF/classes
rather than the root of the jar.
HornetQ
Support for HornetQ has been deprecated. Users of HornetQ should consider migrating to Artemis.
New and Noteworthy
Tip | Check the configuration changelog for a complete overview of the changes in configuration. |
原文:http://www.roncoo.com/article/detail/124575