我正在尝试使用ConfigurationProperties
类来加载我的属性值。一切正常,但使用默认的application.properties
文件。
我需要使用另一个文件,例如app-1.properties
。如何在下面的代码中进行更改。我的意思是,在我的应用程序中,我将使用默认属性文件和自定义属性文件。
我的问题还在于更改此文件的路径,而不仅仅是更改文件名。
@ConfigurationProperties(prefix = "spring.profs")
@Component
public class ProfsProperties {
private String network ;
private String database;
public String getDatabase() {
return database;
}
public String getNetwork() {
return network;
}
public void setDatabase( String database ) {
this.database = database;
}
public void setNetwork( String network ) {
this.network = network;
}
}
我使用此对象的类
@EnableConfigurationProperties
@Configuration
public class questions {
@Autowired
private ProfsProperties profsProperties;
}
我的app-1.properties文件
spring.profs.database = Arnaud
spring.profs.network = Bagna
我还想知道是否必须将@Configuration
与@EnableConfigurationProperties
一起使用吗?
答案 0 :(得分:0)
添加@PropertySource
批注或使用@ConfigurationProperties
中的位置。
示例:
@PropertySource(value = "classpath:abc.properties")
或
@ConfigurationProperties(locations = "classpath:abc.properties", prefix = "info")