Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
207 views
in Technique[技术] by (71.8m points)

java - Can I disable logging of YamlPropertiesFactoryBean when used outside of a spring application context?

I am using YamlPropertiesFactoryBean to load yml configuration files and delegate the heavy binding work to spring. This is done on an existing non spring application. This works well but comes with some default console logging I am struggling to disable.

Is it possible to programmatically disable this default console logging outside of any spring application context ?

I am using spring-boot-starter 2.4.2.

MyConfig loadConfigFromYaml(String ymlFilePath) {
  YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
  yaml.setResources(new FileSystemResource(ymlFile));
  Properties properties = yaml.getObject();
  ConfigurationPropertySource props = new MapConfigurationPropertySource(properties);
  Binder binder = new Binder(props);
  MyConfig config = binder.bind("foo", MyConfig.class).get();
  return MyConfig;
}

When getObject is executed, my console output is populated with :

22:13:37.201 [main] DEBUG org.springframework.beans.factory.config.YamlPropertiesFactoryBean - Loading from YAML: file [...]
22:13:37.223 [main] DEBUG org.springframework.beans.factory.config.YamlPropertiesFactoryBean - Merging document (no matchers set): ...
22:13:37.224 [main] DEBUG org.springframework.beans.factory.config.YamlPropertiesFactoryBean - Loaded 1 document from YAML resource: file [...]

question from:https://stackoverflow.com/questions/66054766/can-i-disable-logging-of-yamlpropertiesfactorybean-when-used-outside-of-a-spring

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...