Saya memiliki banyak kacang Spring yang diambil dari classpath melalui penjelasan, misalnya
@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
// Implementation omitted
}
Di file Spring XML, didefinisikan PropertyPlaceholderConfigurer :
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/app.properties" />
</bean>
Saya ingin menyuntikkan salah satu properti dari app.properites ke dalam kacang yang ditunjukkan di atas. Saya tidak bisa begitu saja melakukan sesuatu
<bean class="com.example.PersonDaoImpl">
<property name="maxResults" value="${results.max}"/>
</bean>
Karena PersonDaoImpl tidak memiliki fitur dalam file Spring XML (ini diambil dari classpath melalui anotasi). Saya punya sejauh berikut:
@Repository("personDao")
public class PersonDaoImpl extends AbstractDaoImpl implements PersonDao {
@Resource(name = "propertyConfigurer")
protected void setProperties(PropertyPlaceholderConfigurer ppc) {
// Now how do I access results.max?
}
}
Tetapi tidak jelas bagi saya bagaimana saya mengakses properti yang saya minati ppc?
PropertyPlaceholderConfigurertidak lagi kelas yang direkomendasikan. Lebih suka PropertySourcesPlaceholderConfigurersebagai gantinya. Bagaimanapun, Anda dapat menggunakan definisi XML yang lebih pendek <context:property-placeholder />.