How to disable accessExternalDTD and entityExpansionLimit warnings with logback

后端 未结 4 896
迷失自我
迷失自我 2021-01-31 17:03

I\'m using logback with groovy and get lots of warnings showing up when parsing xml. I am aware of the bug in JDK1.7_u45 that is causing this.

Warning:  org.apa         


        
4条回答
  •  南旧
    南旧 (楼主)
    2021-01-31 17:26

    If it is not possible to remove xerces from the classpath, you can be more explicit about which factory you want to use, thus avoiding pulling in xerces. Here are two ways of resolving specific factories:

    public static SchemaFactory getSchemaFactory() {
      return schemaFactory =
        SchemaFactory.newInstance(
            "http://www.w3.org/2001/XMLSchema",
            "com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory",
            null);
    }
    
    public static TransformerFactory getTransformerFactory() {
      try {
        final Class transformerFactoryImplClass =
          TransformerFactory.class
              .getClassLoader().loadClass("com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
        final Method factoryGetter =
          transformerFactoryImplClass.getDeclaredMethod("newTransformerFactoryNoServiceLoader");
        return (TransformerFactory) factoryGetter.invoke(null);
      } catch (ClassNotFoundException
        | NoSuchMethodException
        | IllegalAccessException
        | InvocationTargetException e) {
        // fallback in case com.sun.* is not available
        return TransformerFactory.newInstance();
      }
    }
    

提交回复
热议问题