I've a problem in my JUNIT test with Spring boot : the @Value is not resolved. Here the code :
Spring boot config class :
@Configuration
@PropertySource(value="classpath:/config/parametrage-environnement.properties",name="env")
public class ExternalRessourceConfiguration {
//To resolve ${} in @Value
@Bean
public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
return new PropertySourcesPlaceholderConfigurer();
}
}
Class test :
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
@IntegrationTest
public class ConnexionEbicsResourceIntTest {
@Test
@Transactional
public void createConnexionEbics() throws Exception {
restConnexionEbicsMockMvc.perform(post("/api/connexionEbicss")
.contentType(TestUtil.APPLICATION_JSON_UTF8)
.content(TestUtil.convertObjectToJsonBytes(connexionEbicsDTO)))
.andExpect(status().isCreated());
Java ressource :
@RestController
@RequestMapping("/api")
public class ConnexionEbicsResource {
@Value("${env['connexion.proxy.host']}")
//@Value("${connexion.proxy.host}")
public String protocol;
@RequestMapping(value = "/connexionEbicss",
method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<ConnexionEbicsDTO> createConnexionEbics( @RequestBody ConnexionEbicsDTO connexionEbicsDTO) throws URISyntaxException {
log.debug("REST request to save ConnexionEbics : {}", connexionEbicsDTO);
String a = protocol;
}
In java ressource, when I run the test, "a" is null. The @Value was not resolved, why ? My spring boot configuration was ALL bootstraped.
The parametrage-environnement.properties file is located in both paths : src/main/resources/config and src/test/resources/config (copy/paste)