From 3cb52917e34f0b96bb205e1c0dfb1ff0af94bd0b Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Wed, 7 Mar 2018 02:03:54 +1300 Subject: [PATCH] #1335 - Add Try catch to YAML loading ... add system property ebeanSkipYaml ... to enable skipping the read of application.yml (well, all yml) --- .../io/ebean/config/properties/Loader.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/ebean/config/properties/Loader.java b/src/main/java/io/ebean/config/properties/Loader.java index 036b504fa..283b2c6e2 100644 --- a/src/main/java/io/ebean/config/properties/Loader.java +++ b/src/main/java/io/ebean/config/properties/Loader.java @@ -28,16 +28,18 @@ class Loader { private YamlLoader yamlLoader; Loader() { - - try { - Class exists = Class.forName("org.yaml.snakeyaml.Yaml"); - if (exists != null) { - yamlLoader = new YamlLoader(loadContext); - } - } catch (Exception e) { - // ignored - } - } + String skipYaml = System.getProperty("ebeanSkipYaml"); + if (!"true".equals(skipYaml)) { + try { + Class exists = Class.forName("org.yaml.snakeyaml.Yaml"); + if (exists != null) { + yamlLoader = new YamlLoader(loadContext); + } + } catch (Exception e) { + // ignored + } + } + } /** * Load the configuration with the expected ordering. @@ -115,7 +117,11 @@ class Loader { void loadYaml(String resourcePath, Source source) { if (yamlLoader != null) { - yamlLoader.load(resource(resourcePath, source)); + try { + yamlLoader.load(resource(resourcePath, source)); + } catch (Exception e) { + log.warn("Failed to read yml from:" + resourcePath, e); + } } }