有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java属性文件未在Unix计算机上加载,但在windows计算机上也在加载。不明白为什么?

我将Spring4.3.6和Tomcat7用于我们的web应用程序。我的xml文件中有以下配置:-

<bean id="appResourcesProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
  <property name="locations">
    <list>
      <value>classpath*:resources\xxxxxxResources.properties</value>
    </list>
  </property>
</bean> 

这在windows计算机上运行得很好,但在unix计算机上部署相同的时,没有加载属性文件

然后我删除了类路径后面的“*”,并修改如下:-

<bean id="appResourcesProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
  <property name="locations">
    <list>
      <value>classpath:resources\WCApplicationResources.properties</value>
    </list>
  </property>
</bean> 

这在unix机器上运行良好。为什么会这样?我不明白原因。谁能帮我理解这一点。提前感谢


共 (2) 个答案

  1. # 1 楼答案

    Classpath*: portability

    The wildcard classpath relies on the getResources() method of the underlying classloader.... In case an inappropriate result is returned, check the application server documentation for settings that might affect the classloader behavior.

    getResources发现如下内容:

    The name of a resource is a '/'-separated path name that identifies the resource. 
    

    希望对你有所帮助

  2. # 2 楼答案

    原因是“\”,请尝试使用“/”,如resources/WCApplicationResources.properties