2014-10-20 2 views
1

SnakeYaml 1.14를 사용하여 config.yaml을 구문 분석 할 때 "Class not found exception"이 발생합니다. 다음은 구문 분석에 사용되는 코드입니다. 프로젝트를 빌드하기 위해 maven을 사용했습니다.SnakeYaml 클래스가 없습니다.

public class AppConfigurationReader 
{ 
    private static final String CONFIG_FILE = "config.yaml"; 
    private static String fileContents = null; 
    private static final Logger logger = LoggerFactory.getLogger(AppConfigurationReader.class); 

    public static synchronized AppConfiguration getConfiguration() { 
     return getConfiguration(false); 
    } 

    public static synchronized AppConfiguration getConfiguration(Boolean forceReload) { 
     try { 
      Yaml yaml = new Yaml(); 

      if(null == fileContents || forceReload) { 
       fileContents = read(CONFIG_FILE); 
      } 
      yaml.loadAs(fileContents, AppConfiguration.class); 
      return yaml.loadAs(fileContents, AppConfiguration.class); 
     } 
     catch (Exception ex) { 
      ex.printStackTrace(); 
      logger.error("Error loading fileContents {}", ex.getStackTrace()[0]); 
      return null; 
     } 
    } 

    private static String read(String filename) { 
     try { 
      return new Scanner(new File(filename)).useDelimiter("\\A").next(); 
     } catch (Exception ex) { 
      logger.error("Error scanning configuration file {}", filename); 
      return null; 
     } 
    } 
} 

답변

0

나는 유사한 오류가 있지만 dumping a file을 발견했다.

yaml.load 명령어에 클래스의 전체 이름을 쓸 수 있습니다.

yaml.loadAs(fileContents, org.example.package1.AppConfiguration.class); 
: AppConfiguration.classorg.example.package1에 있다면 예를 들어

, 당신은 다음처럼 작성할 수 있습니다