Custom annotation like @Value

后端 未结 3 951
时光说笑
时光说笑 2021-01-13 05:50

I need to create a means to add a custom annotation like

@Value(\"${my.property}\")

However, in my case I need to get the value from a data

3条回答
  •  春和景丽
    2021-01-13 06:44

    Alternatively you should be able to configure kind of properties repository bean and then use it in SpEL directly in @Value annotation.

    Let's say you'd have bean called propertiesRepository in your context that implements following interface:

    interface PropertiesRepository {
        String getProperty(String propertyName);
    }
    

    then on bean where you want to inject values you can use following expression

    @Value("#{propertiesRepository.getProperty('my.property')}")
    String myProperty;
    

提交回复
热议问题