java - Can't pass in YAML Values using Spring -
i have config.yml file looks this
--- name: archive: documentfiles: username: rafa password: hello
my configuration looks this
@configurationproperties(prefix = "name") public class yamlconfig { private list<string> servers = new arraylist<string>(); public list<string> getservers() { return this.servers; } }
in test class, try first value list returned, returns indexoutofboundsexception
know config.yml
values, not passed in. can offer help? below test
@runwith(springjunit4classrunner.class) @contextconfiguration(classes = {applicationconfiguration.class}) public class offlinefileviewerresourcetest { @test public void password(){ fileviewer = new offlinefileviewerresource(); yamlconfig yaml = new yamlconfig(); list<string> list = yaml.getservers(); assertequals("archive", list.get(0)); } }
any of spring annotations (e.g. @configurationproperties
) won't work when you're creating beans manually (with new
):
yamlconfig yaml = new yamlconfig();
to accomplish need, should allow spring manage beans , inject them applicationcontext
tests.
Comments
Post a Comment