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

前端 未结 11 1173
情深已故
情深已故 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:56

    That looks mighty complicated, can't you just do

     
    

    then in code reference:

    @Value("${myProperty}")
    private String myString;
    
    @Value("${myProperty.two}")
    private String myStringTwo;
    

    where some.properties looks something like this

    myProperty = whatever
    myProperty.two = something else\
    that consists of multiline string
    

    For java based config you can do this

    @Configuration
    @PropertySource(value="classpath:some.properties")
    public class SomeService {
    

    And then just inject using @value as before

提交回复
热议问题