在我的目标文件夹中,有2个文件夹,lib和conf.所有属性文件都放在conf文件夹中,而jar放在lib foulder中.
在spring boot之前,我们在spring.xml中使用以下配置来使用@value
<context:property-placeholder location="classpath*:*.properties"/>
Run Code Online (Sandbox Code Playgroud)
在java代码中:
@Value("${name}")
private String name;
Run Code Online (Sandbox Code Playgroud)
但在春季启动时,我不知道如何在java代码中做同样的事情.
我试过跟随,但没有工作
@Configuration
@PropertySource(value = "classpath:aaa.properties")
public class AppConfig {
@Bean
public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
Run Code Online (Sandbox Code Playgroud)