Caused by: org.apache.velocity.exception.VelocityException: Error initializing log: Failed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration. at org.apache.velocity.runtime.RuntimeInstance.initializeLog(RuntimeInstance.java:875) at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:262) at org.apache.velocity.runtime.RuntimeInstance.requireInitialization(RuntimeInstance.java:302) ... 26 more Caused by: 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:220) at org.apache.velocity.runtime.log.LogManager.updateLog(LogManager.java:269) at org.apache.velocity.runtime.RuntimeInstance.initializeLog(RuntimeInstance.java:871) ... 28 more Caused by: java.lang.RuntimeException: Error configuring Log4JLogChute : at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 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) ... 30 more Caused by: java.io.FileNotFoundException: velocity.log (No such file or directory) at java.io.FileOutputStream.open0(Native Method) at java.io.FileOutputStream.open(FileOutputStream.java:270) at java.io.FileOutputStream.<init>(FileOutputStream.java:213) at java.io.FileOutputStream.<init>(FileOutputStream.java:133) at org.apache.log4j.FileAppender.setFile(FileAppender.java:294) at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:207) at org.apache.log4j.FileAppender.<init>(FileAppender.java:110) at org.apache.log4j.RollingFileAppender.<init>(RollingFileAppender.java:79) at org.apache.velocity.runtime.log.Log4JLogChute.initAppender(Log4JLogChute.java:118) ... 32 more
问题原因是velocity的日志框架导致(velocity是使用自己封装的日志框架记录日志的),velocity在初始化Logger时,如果没有读取到配置文件,则会使用默认的velocity.log做为文件输出路径,源代码里使用了 File file = new File(“velocity.log”) 代码片段,这样创建的文件目录是在启动jvm进程的用户目录下(也就是user.dir属性)。
解决办法:
1、添加一个velocity.properties日志配置文件
2、修改velocity的代码,把日志转接到应用里使用的日志框架上来。
3、解决的方式是直接关闭Velocity日志。
在调用 Velocity.init(); 之前
设置:
Velocity.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS, “org.apache.velocity.runtime.log.NullLogChute”);