Using spring3 @Value to access PropertyPlaceholderConfigurer values?

时光总嘲笑我的痴心妄想 提交于 2019-12-01 16:15:10
micfra

Old question, but still worth to be answered. You can use the expression the same way as you would with the original PropertyPlaceholderConfigurer.

app.properties

    app.value=Injected

app-context.xml

    <bean id="propertyConfigurer" class="MyPropertyPlaceholderConfigurer">
      <property name="location">
        <value>file:app.properties</value>
      </property>
    </bean>

in the target bean

    @Value(value="${app.value}")
    private String injected;

Tested this approach using Spring 3.0.6

Have you managed to get it to work by explicitly injecting the value from the bean definition file using the property syntax? In theory, if that works, then you should be able to use the same expression in @Value. For that matter, you should be able to do it using @Autowired @Qualifier also

pakman

I don't think it is possible to access properties loaded by PropertyPlaceHolderConfigurer using SPEL in a @Value annotation. It would be great, but as far as I know, the next best thing is to declare:

<util:properties id="props" location="classpath:xxx/yyy/app.props"/>

It can point to the same properties file as your PropertyPlaceHolderConfigurer.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!