Highlights include:
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.
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.
<properties> <hibernate.version>4.3.11.Final</hibernate.version> </properties>
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).
If you want to register a bean as the JSON components, then you can use @JsonComponent annotation as below:
@JsonComponent public class ModelData{ .... }
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.
The support provided for:
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
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)); } }
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
You can use an image to render the ASCII banner.
If you want to try out these new features and enhancements have a look to this github repository.
Spring Boot Related Topics
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…