Java springmvc中的类路径

Java springmvc中的类路径,java,spring,jakarta-ee,spring-mvc,Java,Spring,Jakarta Ee,Spring Mvc,当我在SpringXML文件中使用类路径属性时,如下所示 <bean class="com.fritolay.suppliernet.common.lastresorthandler.impl.SingletonPropertiesRepository"> <property name="propertiesFile" value="classpath:ecr/sample.properties" /> </bean> 如果有两个不同的项目,则需要确保在部署

当我在SpringXML文件中使用类路径属性时,如下所示

<bean class="com.fritolay.suppliernet.common.lastresorthandler.impl.SingletonPropertiesRepository">
<property name="propertiesFile" value="classpath:ecr/sample.properties" />
</bean>

如果有两个不同的项目,则需要确保在部署web项目时,可以访问java项目中的代码。如果您以分解的方式工作,则需要从web项目访问java项目,在eclipse中很容易做到。

您的java引擎正在该位置查找您的文件(阅读错误):

如您所见,
标记意味着它正在一个临时JAR文件(当然是一个IDE工件)中查找您的文件

您的IDE(或您选择用于部署的工具)似乎没有在JAR中包含属性文件,因此出现了错误。 这可能是因为:

  • 在编译时,您的工具没有将这些资源复制到 编译目标目录(通常为
    /classes
  • 在打包时,您的JAR构建工具不包括
    属性
    将资源放入Jar中,避免它们

在这两种情况下,要修复它,您必须检查构建和部署配置,具体取决于您使用的IDE或工具。

属性文件是否在
ecr
包中?bean本身是否处理类路径资源?是,属性文件在ecr包中。是,在bean类中,其处理资源文件如下。public void setPropertiesFile(Resource propertiesFile)抛出IOException{this.repository.setPropertiesFiles(Collections.singletonMap(DEFAULT_KEY,propertiesFile));}您是否检查了属性文件是否部署在/WEB-INF/classes目录中,或者在打包类的JAR文件中(如果是)?@Tomas:我检查了属性文件是否存在于它引用的位置。在这种情况下,它位于jar文件夹sample-service.jar/ecr中。但是请看“!”马克。它是在JAR文件中查找文件,而不是在文件夹中。你应该在文件C:/Oracle/Middleware/user\u projects/domains/sample/servers/AdminServer/tmp/\u WL\u user/\u appsdir\u supplier-net\u ear/6e86rt/sample-service.JAR中进行检查。谢谢,实际上我想在没有eclipse的情况下部署/构建这个应用程序。在eclipse中,我知道我们可以“添加Project”然后,在使用spring配置之前,测试您是否在正在生成(或输出)的jar中有sample.properties,但在WEB-INF中的ecr文件夹中。我的eclipse建议是您是否以分解的方式工作。
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'propertiesFile' threw exception; nested exception is java.io.FileNotFoundException: class path resource [ecr/sample.properties] cannot be resolved to absolute file path because it does not reside in the file system: zip:C:/Oracle/Middleware/user_projects/domains/sample/servers/AdminServer/tmp/_WL_user/_appsdir_supplier-net_ear/6e86rt/sample-service.jar!/ecr/sample.properties
C:/Oracle/Middleware/user_projects/domains/sample/servers/AdminServer/tmp/_WL_user/_appsdir_supplier-net_ear/6e86rt/sample-service.jar!/ecr/sample.properties