@Value not resolved when using @PropertySource annotation. How to configure PropertySourcesPlaceholderConfigurer?

前端 未结 11 1193
情深已故
情深已故 2020-11-28 23:11

I have following configuration class:

@Configuration
@PropertySource(name = \"props\", value = \"classpath:/app-config.properties\")
@ComponentScan(\"service         


        
11条回答
  •  孤街浪徒
    2020-11-28 23:50

    If you use @PropertySource, properties have to be retrieved with:

    @Autowired
    Environment env;
    // ...
    String subject = env.getProperty("mail.subject");
    

    If you want to retrieve with @Value("${mail.subject}"), you have to register the prop placeholder by xml.

    Reason: https://jira.springsource.org/browse/SPR-8539

提交回复
热议问题