gpt4 book ai didi

java - Spring jar 不加载属性文件

转载 作者:行者123 更新时间:2023-11-29 05:01:34 25 4
gpt4 key购买 nike

我创建了一个使用 restfull 网络服务的客户端应用程序。它是 MAVEN java 项目。我已经在属性文件中定义了 Web 服务的所有 URL。如果我单独运行这个客户端,它工作正常并给出正确的结果。现在我已经创建了同一个应用程序的 jar 并添加到另一个 Web 应用程序的构建路径中。当我部署 Web 应用程序时,出现错误 FileNotFoundException。无法读取 jar 中的属性文件。

    @Autowired
private Environment props;

public String getAllAccounts(){
try {
return restEasyClient.invokeService(props
.getProperty("GET_ALL_ACCOUNTS"));
} catch (Exception e) {
e.printStackTrace();
}
}
}

这是一个代码,作为一个单独的 java 项目工作,而不是作为 web 应用程序中的 jar。

这就是我使用 spring 读取属性文件的方式:

<bean name="props" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:/client.properties</value>
</list>
</property>
</bean>

有什么帮助吗??

最佳答案

您在类路径之后使用/:我认为问题是因为您没有正确到达文件的位置,请考虑此文档 http://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/resources.html#resources-classpath-wildcards还要考虑类路径将在 src/main/resources、src/test/resources、src/main/java 和 src/test/java 中自行查找。

关于java - Spring jar 不加载属性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31963285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com