小编Ben*_*Liu的帖子

Spring启动如何读取jar外的属性文件

在我的目标文件夹中,有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)

configuration spring properties spring-boot

16
推荐指数
4
解决办法
5万
查看次数

标签 统计

configuration ×1

properties ×1

spring ×1

spring-boot ×1