我们最近将应用程序从tomcat7更新到了tomcat9。有了这些,我们还将我们使用的jre从jre 6更新到了openjdk 11。现在一切正常。应用程序启动一个进程,除了日志记录之外,其他一切都在运行。似乎有一个与tomcat记录器和我们的记录器与log4j冲突。我们得到:
SCHWERWIEGEND [main] org.apache.catalina.core.StandardContext.loadOnStartup Servlet [StartupServlet] in web application [/Application] threw load() exception
java.lang.LinkageError: loader constraint violation: when resolving field "log" of type org.apache.log4j.Logger, the class loader org.apache.catalina.loader.ParallelWebappClassLoader @e48059 of the current class, StartupServlet, and the class loader 'app' for the field's defining type, org.fp.Main, have different Class objects for type org.apache.log4j.Logger (StartupServlet is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @e48059, parent loader java.net.URLClassLoader @18f65a4; org.fp.Main is in unnamed module of loader 'app')
at StartupServlet.init(StartupServlet.java:41)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1134)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1089)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:983)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4864)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5173)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1133)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1866)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1045)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:429)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1576)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:309)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423)
at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:366)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:936)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:633)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:343)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:474)
现在我们仍然使用log4j版本1.2.8,并且我们有一个属性文件,在其中我们已经设置了所有内容(模式等)。现在,我们使用该属性文件通过执行以下操作来更改日志路径:
Properties p = new Properties();
p.load(new FileInputStream(Main.Application+File.separator+"log4j.properties"));
p.setProperty("log4j.appender.fileout.File", logPath+File.separator+PRODUKT+".log");
PropertyConfigurator.configure(p);
这以前工作,但现在看来这样做会崩溃的记录器。现在这不会使应用程序崩溃。一切都很好,只是没有日志。
如果我们使用
BasicConfigurator.configure()
好像有用。日志不在我们的日志文件中,但是有一个输出到tomcat日志,看起来不错。有人知道这件事吗?从linkageerrors中我可以看出,在类被修改(通过编译)之后出现了一个问题,而旧类现在不兼容。这意味着,我们将在类路径中设置两个log4jjar。但是类路径看起来不错。我发现tomcat配置了一个logmanager。
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.file=C:/Program Files/Application/tomcat/conf/logging.properties
这是原因吗?一如既往,谢谢你的帮助!
暂无答案!
目前还没有任何答案,快来回答吧!