Mam kilka wiosennych ziaren, które są zbierane ze ścieżki klas za pomocą adnotacji, np
@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
// Implementation omitted
}
W wiosennym pliku XML zdefiniowano właściwość PropertyPlaceholderConfigurer :
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/app.properties" />
</bean>
Chcę wstrzyknąć jedną z właściwości app.properites do pokazanego powyżej komponentu bean. Nie mogę po prostu zrobić czegoś takiego
<bean class="com.example.PersonDaoImpl">
<property name="maxResults" value="${results.max}"/>
</bean>
Ponieważ PersonockeyImpl nie występuje w pliku Spring XML (jest pobierany ze ścieżki klas za pomocą adnotacji). Mam do tego, co następuje:
@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
@Resource(name = "propertyConfigurer")
protected void setProperties(PropertyPlaceholderConfigurer ppc) {
// Now how do I access results.max?
}
}
Ale nie jest dla mnie jasne, jak uzyskać dostęp do nieruchomości, która mnie interesuje ppc
?
PropertyPlaceholderConfigurer
nie jest już zalecaną klasą. Wolę PropertySourcesPlaceholderConfigurer
zamiast tego. W każdym razie możesz użyć krótszej definicji XML <context:property-placeholder />
.