Spring boot ile JUNIT testinde bir sorun yaşıyorum: @Value çözülmedi. İşte kodu:Spring Boot Sınama: Özellik kaynağı ile @Value çözülmedi
Bahar önyükleme yapılandırma sınıfı:
@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();
}
}
Sınıf testi:
@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;
}
Java ressource'da, testi çalıştırdığımda "a" değeri boş. @Value çözülmedi, neden? İlkbahar önyükleme yapılandırmam TÜM önyükleme yapıldı.
parametrage-environnement.properties dosya hem yolları bulunur: src/main/resources/config ve src/test/kaynaklar/config benim denetleyicisi alay edildiği için (kopyala/yapıştır)
Kurucu enjeksiyonu kullandıysanız 'ReflectionTestUtils' kullanımını engelleyebilirsiniz. –