【发布时间】:2022-01-18 14:10:14
【问题描述】:
我有一个 Spring Boot 应用程序,我想从中排除 Spring Boot 中默认创建的 application.properties 并从另一个位置读取它。但是我注意到下面显示的配置文件总是会尝试获取项目中的application.properties 文件。
Config.java 文件:
package com.eMcREY.ChatServiceProject;
import org.springframework.beans.factory.annotation.Value;
@org.springframework.context.annotation.Configuration
public class Config {
// private @Value("${project.testVar:defaultValue}") String test;
// public String getTest() {
// return test;
// }
//
// public void setTest(String test) {
// this.test = test;
// }
// Openfire
private @Value("${openfire.customerKey}") String customerKey;
private @Value("${openfire.customerSecret}") String customerSecret;
private @Value("${openfire.host}") String host;
private @Value("${openfire.port}") int port;
private @Value("${openfire.clientPort}") int clientKey;
public int getClientKey() {
return clientKey;
}
public void setClientKey(int clientKey) {
this.clientKey = clientKey;
}
public String getCustomerKey() {
return customerKey;
}
public void setCustomerKey(String customerKey) {
this.customerKey = customerKey;
}
public String getCustomerSecret() {
return customerSecret;
}
public void setCustomerSecret(String customerSecret) {
this.customerSecret = customerSecret;
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
}
pom:我已将它包含在 pom 中
<configuration>
<excludes>
<exclude>**/*.properties</exclude>
</excludes>
</configuration>
我的问题是如何让这个config 文件从项目外的另一个位置读取application.properties。
谢谢
【问题讨论】:
标签: java spring-boot configuration application.properties