How to programmatically resolve property placeholder in Spring

后端 未结 6 1474
借酒劲吻你
借酒劲吻你 2020-12-04 19:17

I currently work on a web application based on Spring 3.1.0.M1, annotations based, and I have a problem with resolving property placeholders in one specific place of my appl

6条回答
  •  庸人自扰
    2020-12-04 19:50

    Since Spring 3.0.3 there is EmbeddedValueResolverAware which will work same way as mentioned by another post which uses appContext.getBeanFactory().resolveEmbeddedValue("${prop}") call.

    To solve the problem:

    1. Make your class to implement EmbeddedValueResolverAware interface and you will get resolver injected for you

    2. Then where you will be able to retrieve properties as demonstrated in a code snippet:

      String propertyValue = resolver.resolveStringValue("${your.property.name}");
      

    Then your bean does not need to depend on ApplicationContext to retrieve properties you need.

提交回复
热议问题