Highlights include:
- Lots of bug fixes and improvements over M2 (thanks to everyone for trying the milestones).
- Convention based error pages (want a custom 404, just add src/main/resources/public/error/404.html).
- Improved ErrorPage registration support.
- Support for pluggable OAuth2 Principal extraction.
New Features in Spring Boot 1.4
- Executable JAR Layout
- Startup error improvements
- Hibernate 5
- Spring Framework 4.3
- Third Party Library
- Custom JSON Serializer and Deserializer
- New auto-configuration support
- Couchbase
- Neo4j
- Narayana transactional manager
- Caffeine Cache
- Actuator improvements
- Testing improvements
- Datasource binding
- Image Banner
- Summary
Executable JAR Layout
If you are building the JAR file as an executable spring boot application, all the dependencies will be packaged under WEB-INF/lib and application’s own classes will be packages under root of the JAR file. But, spring boot 1.4.0 will package the dependencies under BOOT-INF/lib and application’s own classes under BOOT-INF/classes.
Startup Error Improvements
There is a improvement in displaying the useful error description on startup failures. Prior to 1.4.0, startup failures shows long stack trace that would not show the actual issue unless developer has to read the complete stack trace. But, latest release just shows the cause of the failure and what is the solution.
Hibernate 5
<properties> <hibernate.version>4.3.11.Final</hibernate.version> </properties>
Spring 4.3.0-RC1
In Spring 4.3.0-RC1 there are lots of new features and enhancements. The full list you can find it here. (Also Read : Spring 4 Tutorials).
Third Party Libraries
- Hibernate 5.1
- Jackson 2.7
- Solr 5.5
- Spring Data Hopper
- Spring Session 1.2
- Hazelcast 3.6.
Custom JSON Serializer and Deserializer
If you want to register a bean as the JSON components, then you can use @JsonComponent annotation as below:
@JsonComponent public class ModelData{ .... }
New Auto-Configuration Support
Spring boot adds new auto configuration modules for every release. In this release also there are few more modules added to support the auto-configurations.
- Couchbase
- Neo4j
- Narayana Transaction Manager
- Caffeine Cache
Actuator Improvements
The support provided for:
- Full or partial Git information generated from a build plugin
- Build information generated from the Spring Boot Maven or Gradle plugin.
- Custom information from the Environment (any property starting info.*)
Testing support
The biggest change comes regarding testing support. There are two new modules spring-boot-test and spring-boot-test-autoconfigure
@SpringBootTest
Spring Boot 1.4 tries to simplify this by providing a single @SpringBootTest annotation.
@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @Sql("/init-for-full-integration-test.sql") public class ApplicationTests { @Autowired private TestRestTemplate template; @Test public void random() { ResponseEntity<String> fact = template.getForEntity("/", String.class); assertThat(fact.getBody(), containsString("Chuck Norris sleeps with a pillow under his gun.")); } }
Here as you can see for convenience the injected TestRestTemplate is already configured to make calls against the started server, no need to inject the port with @Value(“${local.server.port}”). However if you would like to know the port there is a better @LocalServerPort annotation.
Testing slices of the application
Sometimes you would like to test a simple “slice” of the application instead of auto-configuring the whole application. Spring Boot 1.4 introduces 3 new test annotations:
- @WebMvcTest – for testing the controller layer
- @JsonTest – for testing the JSON marshalling and unmarshalling
- @DataJpaTest – for testing the repository layer
@WebMvcTest
In order to test only the controller layer or often a single controller the @WebMvcTest used in combination with @MockBean can be handy. @Service or @Repository components will not be scanned.
@RunWith(SpringRunner.class) @WebMvcTest(ChuckNorrisFactController.class) public class CheckNorrisFactControllerTests { @Autowired private MockMvc mvc; @MockBean private ChuckNorrisFactService chuckNorrisFactService; @Test public void getOneRandomly() throws Exception { given(chuckNorrisFactService.getOneRandomly()).willReturn(new ChuckNorrisFact("Chuck Norris counted to infinity twice.")); mvc.perform(get("/").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(content().json("{'fact':'Chuck Norris counted to infinity twice.'}")); } }
@JsonTest
To test JSON marshalling and unmarshalling you can use the @JsonTest annotation. @JsonTest will auto-configure Jackson ObjectMappers and @JsonComponent beans
@RunWith(SpringRunner.class) @JsonTest public class ChuckNorrisFactJsonTests { private JacksonTester json; @Test public void serialize() throws IOException { ChuckNorrisFact fact = new ChuckNorrisFact("When Chuck Norris turned 18, his parents moved out."); JsonContent write = this.json.write(fact); assertThat(this.json.write(fact)).isEqualToJson("expected.json"); } @Test public void deserialize() throws IOException { String content = "{"fact":"Chuck Norris knows Victoria's secret."}"; assertThat(this.json.parse(content)).isEqualTo(new ChuckNorrisFact("Chuck Norris knows Victoria's secret.")); } }
@DataJpaTest
To test the JPA layer of an application you can use @DataJpaTest. By default it configures an in-memory database, scans for @Entity classes and configures the Spring Data JPA repositories. @Service, @Controller, @RestController beans will not be loaded.
@RunWith(SpringRunner.class) @DataJpaTest public class ChuckNorrisFactRepositoryTests { @Autowired private TestEntityManager entityManager; @Autowired private ChuckNorrisFactRepository repository; @Test public void getOneRandomly() { String fact = "If at first you don't succeed, you're not Chuck Norris."; entityManager.persist(new ChuckNorrisFact(fact)); List<ChuckNorrisFact> facts = repository.getOneRandomly(new PageRequest(0, 10)); assertThat(facts.get(0).getText(), is(fact)); } }
Datasource binding
In Spring Boot 1.4 via spring.datasource property namespace only the common datasource properties are set. For datasource provider specific ones new namespaces were introduced.
spring.datasource.hikari.maximum-pool-size=5 spring.datasource.hikari.connection-timeout=10
Image Banners
You can use an image to render the ASCII banner.
Summary
If you want to try out these new features and enhancements have a look to this github repository.
Spring Boot Related Topics
- Introduction to Spring Boot
- Essentials and Key Components of Spring Boot
- Spring Boot CLI Installation and Hello World Example
- Spring Boot Initializr Web Interface
- Spring Boot Initializr With IDEs
- Spring Boot Initializr With Spring Boot CLI
- Installing Spring Boot
- Developing your first Spring Boot application
- External Configurations for Spring Boot Applications
- Logging Configuration in Spring Boot
- Spring Boot and Spring MVC
- Working with SQL Databases and Spring Boot
- MySQL Configurations
- Spring Data JPA using Spring Boot Application
- Spring Boot with NoSQL technologies
- Spring Cache Tutorial
- Spring Security Tutorial with Spring Boot
- Spring Boot and MongoDB in REST Application
- Complete Guide for Spring Boot Actuator
- Microservices with Spring Boot