gpt4 book ai didi

java - Spring应用程序看不到具有属性扩展名的文件(application.properties除外)

转载 作者:行者123 更新时间:2023-11-30 05:24:13 25 4
gpt4 key购买 nike

我正在开发一个 Spring Boot Web 应用程序,需要从 homepage.properties 文件获取一些数值数据。

但是,thymeleaf 模板 View 不会呈现除 application.properties 之外的文件中的任何属性,即使 .properties 文件位于同一文件夹内也是如此。

src > main > resources > application.properties (gets properties successfully)

src > main > resources > homepage.properties (does not get properties)

这是一个简单的用法:

application.properties

working.hours=650

主页.属性

test.hours=30

index.html

<h1 class="lan_fun_value mb-1" th:text="${@environment.getProperty('working.hours)}"></h1> //renders 650
<h1 class="lan_fun_value mb-1" th:text="${@environment.getProperty('test.hours)}"></h1> //renders nothing

有什么想法可能是什么问题吗?

最佳答案

您可以使用@PropertySources加载多个属性文件。您可以在应用程序类上方编写以下代码。

@SpringBootApplication
@PropertySources({
@PropertySource("application.properties"),
@PropertySource("homepage.properties")
})
public class Application{

}

您必须在 working.hourstest.hours 之后添加单引号。

关于java - Spring应用程序看不到具有属性扩展名的文件(application.properties除外),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59001967/

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