为什么在拥有@enableasync配置时需要安装propertysourcesplaceplaceconfigurerbean

huwehgph  于 2021-07-23  发布在  Java
关注(0)|答案(0)|浏览(161)

我有以下配置类:

@Configuration
public class AppConfig {

    @Value("${my.value}"
    private String myValue;

    // The rest of the code
}

它运行良好 my.value 从属性分配给 myValue .
但如果我加上 @EnableAsync 对此类的注解,它不起作用。

@Configuration
@EnableAsync
public class AppConfig {

    @Value("${my.value}"
    private String myValue;

    // The rest of the code
}

这是错误:
原因:org.springframework.beans.factory.unsatifieddependencyException
可以通过添加 PropertySourcesPlaceholderConfigurer 班上的豆子。

@Configuration
@EnableAsync
public class AppConfig {

    @Value("${my.value}"
    private String myValue;

    @Bean
    public static PropertySourcesPlaceholderConfigurer propertyConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }

    // The rest of the code
}

有人能解释一下为什么需要示例化它吗 PropertySourcesPlaceholderConfigurer 吃豆子的时候 @EnableAsync 注解?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题