速度和对数中的错误4J

2022-09-02 11:30:13

我构建了一个Web应用程序,它可以在我的本地主机(tomcat)中很好地工作。但是当我尝试部署时,速度在init()中崩溃,给我留下了这个奇怪的堆栈跟踪(抱歉大小):


ERROR [main] (VelocityConfigurator.java:62) - Error initializing Velocity!
org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration.
    at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:206)
    at org.apache.velocity.runtime.log.LogManager.updateLog(LogManager.java:255)
    at org.apache.velocity.runtime.RuntimeInstance.initializeLog(RuntimeInstance.java:795)
    at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:250)
    at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:589)
    at org.apache.velocity.runtime.RuntimeSingleton.init(RuntimeSingleton.java:229)
    at org.apache.velocity.app.Velocity.init(Velocity.java:107)
    at com.webcodei.velociraptor.velocity.VelocityConfigurator.initVelocity(VelocityConfigurator.java:57)
    at com.webcodei.velociraptor.velocity.VelocityConfigurator.configure(VelocityConfigurator.java:42)
    at com.webcodei.velociraptor.VelociListener.contextInitialized(VelociListener.java:26)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4336)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:761)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:741)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1023)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1015)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:448)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.lang.RuntimeException: Error configuring Log4JLogChute : 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.apache.velocity.util.ExceptionUtils.createWithCause(ExceptionUtils.java:67)
    at org.apache.velocity.util.ExceptionUtils.createRuntimeException(ExceptionUtils.java:45)
    at org.apache.velocity.runtime.log.Log4JLogChute.initAppender(Log4JLogChute.java:133)
    at org.apache.velocity.runtime.log.Log4JLogChute.init(Log4JLogChute.java:85)
    at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:157)
    ... 33 more
Caused by: java.io.FileNotFoundException: velocity.log (Permission denied)
    at java.io.FileOutputStream.openAppend(Native Method)
    at java.io.FileOutputStream.(FileOutputStream.java:177)
    at java.io.FileOutputStream.(FileOutputStream.java:102)
    at org.apache.log4j.FileAppender.setFile(FileAppender.java:290)
    at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:194)
    at org.apache.log4j.FileAppender.(FileAppender.java:109)
    at org.apache.log4j.RollingFileAppender.(RollingFileAppender.java:72)
    at org.apache.velocity.runtime.log.Log4JLogChute.initAppender(Log4JLogChute.java:118)
    ... 35 more
ERROR [main] (VelocityConfigurator.java:63) - java.lang.RuntimeException: Error configuring Log4JLogChute : 
org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration.
    at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:206)
    at org.apache.velocity.runtime.log.LogManager.updateLog(LogManager.java:255)
    at org.apache.velocity.runtime.RuntimeInstance.initializeLog(RuntimeInstance.java:795)
    at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:250)
    at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:589)
    at org.apache.velocity.runtime.RuntimeSingleton.init(RuntimeSingleton.java:229)
    at org.apache.velocity.app.Velocity.init(Velocity.java:107)
    at com.webcodei.velociraptor.velocity.VelocityConfigurator.initVelocity(VelocityConfigurator.java:57)
    at com.webcodei.velociraptor.velocity.VelocityConfigurator.configure(VelocityConfigurator.java:42)
    at com.webcodei.velociraptor.VelociListener.contextInitialized(VelociListener.java:26)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4336)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:761)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:741)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1023)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1015)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:448)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.lang.RuntimeException: Error configuring Log4JLogChute : 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.apache.velocity.util.ExceptionUtils.createWithCause(ExceptionUtils.java:67)
    at org.apache.velocity.util.ExceptionUtils.createRuntimeException(ExceptionUtils.java:45)
    at org.apache.velocity.runtime.log.Log4JLogChute.initAppender(Log4JLogChute.java:133)
    at org.apache.velocity.runtime.log.Log4JLogChute.init(Log4JLogChute.java:85)
    at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:157)
    ... 33 more
Caused by: java.io.FileNotFoundException: velocity.log (Permission denied)
    at java.io.FileOutputStream.openAppend(Native Method)
    at java.io.FileOutputStream.(FileOutputStream.java:177)
    at java.io.FileOutputStream.(FileOutputStream.java:102)
    at org.apache.log4j.FileAppender.setFile(FileAppender.java:290)
    at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:194)
    at org.apache.log4j.FileAppender.(FileAppender.java:109)
    at org.apache.log4j.RollingFileAppender.(RollingFileAppender.java:72)
    at org.apache.velocity.runtime.log.Log4JLogChute.initAppender(Log4JLogChute.java:118)
    ... 35 more
ERROR [main] (VelocityConfigurator.java:64) - Failed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration.
org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration.
    at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:206)
    at org.apache.velocity.runtime.log.LogManager.updateLog(LogManager.java:255)
    at org.apache.velocity.runtime.RuntimeInstance.initializeLog(RuntimeInstance.java:795)
    at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:250)
    at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:589)
    at org.apache.velocity.runtime.RuntimeSingleton.init(RuntimeSingleton.java:229)
    at org.apache.velocity.app.Velocity.init(Velocity.java:107)
    at com.webcodei.velociraptor.velocity.VelocityConfigurator.initVelocity(VelocityConfigurator.java:57)
    at com.webcodei.velociraptor.velocity.VelocityConfigurator.configure(VelocityConfigurator.java:42)
    at com.webcodei.velociraptor.VelociListener.contextInitialized(VelociListener.java:26)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4336)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:761)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:741)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1023)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1015)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:448)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.lang.RuntimeException: Error configuring Log4JLogChute : 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.apache.velocity.util.ExceptionUtils.createWithCause(ExceptionUtils.java:67)
    at org.apache.velocity.util.ExceptionUtils.createRuntimeException(ExceptionUtils.java:45)
    at org.apache.velocity.runtime.log.Log4JLogChute.initAppender(Log4JLogChute.java:133)
    at org.apache.velocity.runtime.log.Log4JLogChute.init(Log4JLogChute.java:85)
    at org.apache.velocity.runtime.log.LogManager.createLogChute(LogManager.java:157)
    ... 33 more
Caused by: java.io.FileNotFoundException: velocity.log (Permission denied)
    at java.io.FileOutputStream.openAppend(Native Method)
    at java.io.FileOutputStream.(FileOutputStream.java:177)
    at java.io.FileOutputStream.(FileOutputStream.java:102)
    at org.apache.log4j.FileAppender.setFile(FileAppender.java:290)
    at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:194)
    at org.apache.log4j.FileAppender.(FileAppender.java:109)
    at org.apache.log4j.RollingFileAppender.(RollingFileAppender.java:72)
    at org.apache.velocity.runtime.log.Log4JLogChute.initAppender(Log4JLogChute.java:118)
    ... 35 more


有谁知道解决方法吗?或者至少理解了这个错误?我做了一些谷歌搜索,但没有线索。只有这个页面面临同样的问题,但没有解决方案。


答案 1

Velocity试图将日志文件放在Tomcat开始的目录中,我相信这实际上是/。

您可以通过将以下行添加到您的速度属性中来强制 Velocity 登录到 Tomcat 的标准日志:

runtime.log.logsystem.class=org.apache.velocity.runtime.log.SimpleLog4JLogSystem
runtime.log.logsystem.log4j.category=velocity
runtime.log.logsystem.log4j.logger=velocity

velocity.properties 应该进入 /WEB-INF/velocity.properties,但你可以在 web.xml 的 servlet 定义中覆盖它。

如果您按属性而不是速度初始化 Velocity,则:

VelocityEngine engine = new VelocityEngine();

Properties props = new Properties();
props.put("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.SimpleLog4JLogSystem");
props.put("runtime.log.logsystem.log4j.category", "velocity");
props.put("runtime.log.logsystem.log4j.logger", "velocity");

engine.init(props);

在此处阅读更多内容:

http://velocity.apache.org/engine/devel/developer-guide.html#usinglog4jwithexistinglogger

和这里:

http://minaret.biz/tips/tomcatLogging.html#velocity


答案 2

我认为这条线有答案。创建速度.log文件时似乎存在问题。您的配置文件是什么样的?

Caused by: java.io.FileNotFoundException: velocity.log (Permission denied)

推荐