Caused by: java.io.FileNotFoundException: velocity.log (No such file or directory)

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”);

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值