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

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

I have following configuration class:

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


        
11条回答
  •  -上瘾入骨i
    2020-11-28 23:56

    I had the very same problem. @PropertySource is not playing well with @Value. A quick workaround is to have an XML configuration which you'll refer to it from your Spring Java Configuration using @ImportResource as usual and that XML configuration file will include a single entry: (of course with the needed namespace ceremony). Without any other change @Value will inject properties in your @Configuration pojo.

提交回复
热议问题