This reference by @phillip_webb is a really good in depth introduction into all details of spring boot. Even though it's not about spring-data and all the other spring projects, it always provides as much information, which is necessary to understand what's spring boots role in the play.
The 24. Externalized Configuration section explains very well, how a spring boot application can be configured.
The [40. Testing] chapter is in my opinion not good enough, when it comes to testing with e.g. MockMvc
and values of
the application.yml
(e.g. for @Value
or SpEL
).
In my use case I moved from the suggested version to this working version:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = HttpResponseHeadersTestApplication.class)
@WebAppConfiguration
@IntegrationTest("server.port:0")
public class ExpressionControllerTest
{
private MockMvc mockMvc;
@Autowired
private WebApplicationContext webApplicationContext;
@Before
public void setUp() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
@Test
public void testValueExpression() throws Exception {
MockHttpServletResponse response = this.mockMvc
.perform(MockMvcRequestBuilders
.get("/handleValueExpression"))
.andReturn().getResponse();
assertNotNull(response.getHeader("X-Key"));
assertTrue(response.getHeader("X-Key").equals("X-Value-Method"));
assertEquals(1, response.getHeaderNames().size());
}
}
If somebody has a better (RestTemplate-based? - and more spring like) way how to handle that: you are welcome!
The 303 pages are a must read for everyone getting started with spring boot!