java - Spring boot integration test with SpringApplicationConfiguration doesn't seem to resolve @Value annotation -
i have integration test set like:
@runwith(springjunit4classrunner.class) @springapplicationconfiguration(classes = {xmlfilesplitter.class, ...}) public class xmlfilesplittertests { ..
in xmlfilesplitter
have property annotated @value("${default.output.file}")
, value retrieved application.properties
. works fine when running app normally. when running integration test, value not resolved (it "${default.output.file}
"). when debugged through code resolving placeholder noticed org.springframework.beans.factory.support.abstractbeanfactory embeddedvalueresolvers
empty in test, while containing propertysourcesplaceholderconfigurer
when running app normally.
i saw normal run has propertyplaceholderautoconfiguration
spring-boot-autoconfigure configure propertyplaceholder , figured needed add class springapplicationconfiguration
classes have configured integration test. added it:
@springapplicationconfiguration(classes = {xmlfilesplitter.class, ... , propertyplaceholderautoconfiguration.class})
and indeeds resolves @value
annotation (with value application.properties).
however feels wrong, adding knowledge of class test. question how solve properly?
Comments
Post a Comment