Log4j FileNotFoundException - Java FileSystem getBooleanAttributes()方法如何工作?

时间:2017-02-01 20:20:01

标签: java spring tomcat log4j filesystems

问题:

我在两个不同的工作区检查了相同的maven项目。导入eclipse。清洗。建造它们。发布到Tomcat。

启动服务器时,一个设置就能找到log4j路径(类似Linux)。另一个确切的设置是无法找到路径并引发以下错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'log4jInitialization' defined in URL [jar:file:/D:/apache-tomcat-7.0.50-old/wtpwebapps/DevCom-War/WEB-INF/lib/DevCom-Remittance-1.1.0-SNAPSHOT.jar!/config/applicationContext.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: Log4j config file [/home/deployment/devcom/config/devCom_log4j.properties] not found

如果我在D:的{​​{1}}前面添加/home/deployment/devcom/config/devCom_log4j.properties,则只有其他设置会识别该路径并且不会抛出错误。

  

为什么第一个设置能够识别并使用类似linux的路径   而第二个设置没有?

     

在所有涉及的实体中,问题可能在哪里?   Eclipse,Maven,Tomcat,SVN Eclipse插件......?

eclipse中的Tomcat配置:(使用Tomcat安装)

devCom.properties

Spring配置:

-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -Xms712m -Xmx712m -XX:PermSize=256m -XX:MaxPermSize=356m -Dcatalina.base="D:\apache-tomcat-7.0.50-old" -Dcatalina.home="D:\apache-tomcat-7.0.50-old" -Dwtp.deploy="D:\apache-tomcat-7.0.50-old\wtpwebapps" -Djava.endorsed.dirs="D:\apache-tomcat-7.0.50-old\endorsed" -Dext.prop.dir="D:\home\deployment" -Denv.prop="dev"

d:\家\部署\ devcom \配置\ devCom.properties:

<bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>file:///${ext.prop.dir}/devcom/config/devCom.properties</value>
        </property>
        <property name="ignoreUnresolvablePlaceholders">
            <value>true</value>
        </property>
</bean>


<bean id="log4jInitialization" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
      <property name="targetClass" value="org.springframework.util.Log4jConfigurer"/>
      <property name="targetMethod" value="initLogging"/>
      <property name="arguments">
         <list>
            <value>${log4j.config.location}</value>
            <value>${log4j.refresh.interval}</value>
         </list>
      </property>
</bean>

(请注意linux之类的路径。)

log4j.config.location = /home/deployment/devcom/config/devCom_log4j.properties

项目详情:

Windows 10

JDK 8

Spring 3.0.5

Tomcat 7

的Maven

Eclipse Mars

Log4jConfigurer initLogging:

log4j.refresh.interval = 100000

档案存在():

public static void initLogging(String location, long refreshInterval) throws FileNotFoundException {
    String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(location);
    File file = ResourceUtils.getFile(resolvedLocation);
    if (!file.exists()) {
        throw new FileNotFoundException("Log4j config file [" + resolvedLocation + "] not found");
    }
}

最后public boolean exists() { SecurityManager security = System.getSecurityManager(); if (security != null) { security.checkRead(path); } if (isInvalid()) { return false; } return ((fs.getBooleanAttributes(this) & FileSystem.BA_EXISTS) != 0); // first setup -> 3 & 1. second setup -> 0 & 1 !!! What does it mean? How does it work? } 方法如何工作?缩小这个问题的来源是否有帮助?

感谢。

1 个答案:

答案 0 :(得分:1)

FileSystem的{​​{1}}返回:

  

返回表示的文件或目录的简单布尔属性     由给定的抽象路径名,如果它不存在或一些,则为零     发生其他I / O错误

这意味着它返回getBooleanAttributesread: 4write: 2的总和(例如,所有三个都可用,意味着7)。

我希望您的第二次设置的行为在Windows下正常,这是指定execute: 1路径的预期方式。

我建议你尝试发现两个环境之间的配置差异:配置选项,用户权限,文件系统访问等等