小编Chr*_*ley的帖子

如何使用 Hibernate 的 ClassLoaderService 注册自定义类加载器?

背景

我有一组 Groovy 文件,我使用 Groovy 的类加载器将它们解析为类:

    GroovyClassLoader gcl = new GroovyClassLoader();
    while (groovyIter.hasNext()) {
      File groovyFile = (File) groovyIter.next();
      try {
        Class clazz = gcl.parseClass(groovyFile);
      } catch (IOException ioe) {
        log.error("Unable to read file " + groovyFile + " to parse class ", ioe);
      }
    }
Run Code Online (Sandbox Code Playgroud)

GroovyClassLoader 完成后,我使用 XStream 解析 XML 文件,将 XML 反序列化为 Groovy 对象的不同实例。我现在从一种类型开始:发票。为了让 XStream 可以看到 groovy 类,我将类加载器设置为 GroovyClassLoader 的实例。

  XStream xstream = new XStream();
  xstream.setClassLoader(gcl); 

  // Read the file and get objects
  Object deserialized = xstream.fromXML(file);
Run Code Online (Sandbox Code Playgroud)

获得反序列化对象后,我想使用 …

groovy hibernate classloader

5
推荐指数
0
解决办法
2023
查看次数

标签 统计

classloader ×1

groovy ×1

hibernate ×1