这是this问题的副本,但是那里提出的解决方案对我不起作用,我还不能发表评论。
标题本身解释了这个问题:即使使用.json
文件中的log4j.configurationFactory=org.apache.logging.log4j.core.config.json.JsonConfigurationFactory
正确配置,Log4j2也无法使用log4j2.component.properties
配置文件。
完整的错误堆栈跟踪是:
[Fatal Error] log4j2.json:1:1: Content is not allowed in prolog.
ERROR StatusLogger Error parsing /Users/sm/cdss-scala/risk-stratification/src/main/resources/log4j2.json
org.xml.sax.SAXParseException; systemId: file:///Users/sm/cdss-scala/risk-stratification/src/main/resources/log4j2.json; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:257)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339)
at org.apache.logging.log4j.core.config.xml.XmlConfiguration.<init>(XmlConfiguration.java:95)
at org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory.getConfiguration(XmlConfigurationFactory.java:46)
at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:491)
at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:420)
at org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:265)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:613)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:634)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:229)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:152)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.logging.log4j.scala.Logger$.apply(Logger.scala:39)
at org.apache.logging.log4j.scala.Logging$class.$init$(Logging.scala:28)
at eu.connecare.cdss.hadrian.HadrianService$.<init>(HadrianService.scala:11)
at eu.connecare.cdss.hadrian.HadrianService$.<clinit>(HadrianService.scala)
at eu.connecare.cdss.hadrian.HadrianService.runEngine(HadrianService.scala)
at eu.connecare.cdss.hadrian.HadrianLaunchable.main(HadrianLaunchable.java:6)
ERROR StatusLogger No logging configuration
答案 0 :(得分:0)
根据我的经验,用你的json文件显示你的json配置是没有用的。尝试在json文件中添加/删除BOM。
Waht的BOM以及如何删除BOM,请参见此处: Byte order mark