У меня есть куча бинов Spring, которые берутся из пути к классам через аннотации, например.
@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
// Implementation omitted
}
В XML-файле Spring есть PropertyPlaceholderConfigurer определено:
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/app.properties" />
</bean>
Я хочу ввести одно из свойств из app.properites в bean-компонент, показанный выше. Я не могу просто сделать что-то вроде
<bean class="com.example.PersonDaoImpl">
<property name="maxResults" value="${results.max}"/>
</bean>
Поскольку PersonDaoImpl не присутствует в XML-файле Spring (он выбирается из пути к классам через аннотации). Я получил следующее:
@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
@Resource(name = "propertyConfigurer")
protected void setProperties(PropertyPlaceholderConfigurer ppc) {
// Now how do I access results.max?
}
}
Но мне непонятно, как получить доступ к интересующей меня собственности из ppc
?
PropertyPlaceholderConfigurer
больше не является рекомендуемым классом. Вместо этого предпочитайтеPropertySourcesPlaceholderConfigurer
. В любом случае вы можете использовать более короткое определение XML<context:property-placeholder />
. - person Michael Piefel   schedule 30.10.2013